url rewriting "double path for same file" - apache

I have an issue with my htaccess file but I dont understand where the mistake comes from:
Ex:
I have the following file in my folder
contact.php
I did a basic rewrite like that
RewriteRule ^about/$ contact.php [L]
so now my contact page is accessible from http://localhost/project/about/
the problem is that page is also accessible from
http://localhost/project/contact/
Why is this happening?
How can I disallow that?
Thanks for all your answers!

That is due to enabling of option MultiViews. Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.
To disallow this you can add this line on top of your .htaccess:
Options -MultiViews

Related

RewriteEngine is not working [.htaccess]

ReWrite Engine is not working, i'm using 000Webhost as my Web Hosting Service Provider and i'm on free plan.
Problems:
1.) When I go to my domain (without subdomains) like prospekt.ml, i'm gonna be redirected to 000Webhost 404 Error.
2.) When I tried to test my .htaccess if it's working. It's supposed to rewrite the url and add a vanity url. like (user/astroXoom) but instead of that, i'm getting redirected to 000Webhost 404 Error.
The .htaccess file is placed on my public_html folder. It should redirect to "member/user/username.php?username=$1"
Screenshot of my
public_html
Thank you and have a good day!
Edit:
This is my .htaccess file
# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteBase /
# Fancy Indexing
Options Indexes
IndexOptions FancyIndexing NameWidth=80 ScanHTMLTitles
IndexOrderDefault Ascending Date
IndexIgnore *.jpg *.png
# Rewrite for Users
RewriteEngine on
RewriteRule ^member/user/([^/]+)$ member/user/username.php?username=$1 [L,QSA]
On 000webhost server you have to use an absolute rewrite path (starting with /) or RewriteBase directive to map the rewritten url to correct location as 000webhost server uses virtual user home directory, so it's important to add a RewriteBase directive when you are using a relative path in Rewrite target, otherwise you will get a 404 not found.
Source :
https://www.000webhost.com/faq.php?ID=16

symfony2 application on godaddy: no input file specified

I deployed a symfony2 application on godaddy and I got this error: no input file specified. After some research I managed to solve with some changes on .htaccess file:
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php/ [QSA,L]
</IfModule>
this works but only for urls like /mycontroller, I still get errors when using urls like /mycontroller/newaction. what else can I change to manage it working? thanks
Here is a good post how to fix that problem.
When getting started with Symfony2 using Apache and fast-cgi for PHP, you may get the following message come up when trying to open up
the /app_dev.php/demo URL.
No input file specified. This occurs because the url rewrite module isn’t passing along the pathinfo details properly to the fcgi
php. Here’s how you can fix it.
1.) Open the relavent php.ini file
2.) Look for the cgi.fix_pathinfo setting.
3.) You’ll most likely find it set to 0.
4.) Change it so that it reads cgi.fix_pathinfo=1
5.) Save the changes. Restart Apache.
6.) Try loading up /app_dev.php/demo/. It should work now.
http://wilt.isaac.su/articles/symfony2-no-input-file-specified-

mod_rewrite URI with same name as folder or files

A simple .htaccess file with this:
RewriteEngine On
RewriteBase /
RewriteRule ^webshop$ /index.php?page=webshop [L]
... does not work for me because a have a file called webshop.php in the web root. Renaming the file solves the poblem, and changing the regex in the .htaccess file solves the problem, but still - it's only a partial match of the file name...? The only thing I can find on this is to use
DirectorySlash off
I've tried that and it made no difference.
Need some help here, there must be a pretty simple solution to this.
Most likely you have MultiViews options enabled. Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.
Disable it by placing this line on top of your .htaccess:
Options -MultiViews

.htaccess RewriteRule and FallbackResource don't work

I'm testing stuff on localhost, and this is my .htaccess file:
RewriteEngine On
RewriteRule ^login/?$ login.php [NC,L]
FallbackResource error.php
in my root directory (/var/www). It just doesn't work. I've already set the "AllowOverride All" in the configuration file: if I put garbage in .htaccess file I get an internal server error (and not a 404), meaning (I think) that the AllowOverride is set properly.
I get "Module rewrite already enabled" if I give "a2enmod rewrite" and, of course, I restarted apache.
Any suggestion? I don't know where to look.
I had the same problem. I found that this error occured only when I tried to access an address with the .php extension. If for example I tried to access test.mydomain.com/home.php, I would get a 404 error. If, however, I tried to access test.mydomain.com/home.html, I had no problem. So I thought it had to do with php interfering with the redirection.
Turns out I had to comment out the following line in my public_html .htaccess file:
#AddHandler application/x-httpd-php5s .php
After that, I could access files in the webroot folder.

Rewrite url rules in .htaccess inside a directory

I'm trying to use rewrite url rules using a .htaccess file. This seems to work fine in my main .htaccess file (only works for php pages which exist in same directory), but when I want to use another .htaccess for php file inside a subdirectory the rules don't apply at all and I get a 404 error page.
The file I want to point to is /news/story.php. story.php requests an integer variable called 'article' to fetch the article from database and display it.
So basically what I want to do is replace http://www.mydomain.com/news/story.php?article=1
with http://www.mydomain.com/news/story/article/1/
I'm using the following rules in the .htaccess file which is inside the 'news' directory.
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
RewriteEngine on
RewriteRule story/article/(.*)/ story.php?article=$1
RewriteRule story/article/(.*) story.php?article=$1
Thanks for your help
RewriteRule story/article/(.*)/ news/story.php?article=$1
RewriteRule story/article/(.*) news/story.php?article=$1