Reputation: 829
I'm using .htaccess for better URLs.
I have this php page:
treatments-line.php
With
#rewrite treatments-line
RewriteRule ^/?treatments/line/([0-9]+)$ treatments-line.php?id=$1 [NC,L]
I can successfully enter the page /treatments/line/the_id_of_the_page.
But when I create a page treatments.php, the rewrite of treatments-line doesn't work, it simply shows the frontpage.
For a test when I change the rewrite method into this:
#rewrite treatments-line
RewriteRule ^/?treatment/line/([0-9]+)$ treatments-line.php?id=$1 [NC,L]
I've just changed the name into treatment (without "s"), the rewrite on /treatment/line/the_id_of_the_page works fine, but I don't want to change the name.
So, I can see that there's a conflict with the name, because of treatments.php file.
How can I fix that?
These two PHP pages are in root directory of the website.
EDIT2:
Here's my whole .htaccess code:
Options -MultiViews
RewriteEngine on
#remove .php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_URL} /(.*)$
RewriteRule ^(.*)$ %1.php [NC,L]
#redirect posts-view
RewriteRule ^/?post/([0-9]+)$ posts-view.php?id=$1 [NC,L]
#rewrite products-zone
RewriteRule ^/?products/zone/([0-9]+)$ products-zone.php?id=$1 [NC,L]
#rewrite products-category
RewriteRule ^/?products/category/([0-9]+)$ products-category.php?id=$1 [NC,L]
#rewrite products-solution
RewriteRule ^/?products/solution/([0-9]+)$ products-solution.php?id=$1 [NC,L]
#rewrite products-line
RewriteRule ^/?products/line/([0-9]+)$ products-line.php?id=$1 [NC,L]
#rewrite treatments-line
RewriteRule ^/?treatments/line/([0-9]+)$ treatments-line.php?id=$1 [NC,L]
#rewrite treatments-category
RewriteRule ^/?treatments/category/([0-9]+)$ treatments-category.php?id=$1 [NC,L]
#rewrite product-view
RewriteRule ^/?products/([0-9]+)$ product-view.php?id=$1 [NC,L]
#redirect lang
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/(.*)$ $2.php?lang=$1 [L]
#RewriteRule ^([^\.]+)/?$ index.php?lang=$1 [L]
Upvotes: 1
Views: 66
Reputation: 1702
Options -MultiViews
RewriteEngine On
RewriteRule ^/?treatments/line/([0-9]+)$ treatments-line.php?id=$1 [NC,L]
Adding Options -MultiViews
solves you the issue.
For more information about Options -MultiViews
:
A MultiViews search is enabled by the MultiViews Options. If the server receives a request for /some/dir/foo and /some/dir/foo does not exist, then the server reads the directory looking for all files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements, and returns that document.
http://httpd.apache.org/docs/2.2/en/mod/mod_negotiation.html#multiviews
Based on your .htaccess code and also the comments, you need to change the position of the #remove .php
rule to the very end of the .htaccess. So, this is how your .htaccess code should be like:
Options -MultiViews
RewriteEngine on
#redirect posts-view
RewriteRule ^/?post/([0-9]+)$ posts-view.php?id=$1 [NC,L]
#rewrite products-zone
RewriteRule ^/?products/zone/([0-9]+)$ products-zone.php?id=$1 [NC,L]
#rewrite products-category
RewriteRule ^/?products/category/([0-9]+)$ products-category.php?id=$1 [NC,L]
#rewrite products-solution
RewriteRule ^/?products/solution/([0-9]+)$ products-solution.php?id=$1 [NC,L]
#rewrite products-line
RewriteRule ^/?products/line/([0-9]+)$ products-line.php?id=$1 [NC,L]
#rewrite treatments-line
RewriteRule ^/?treatments/line/([0-9]+)$ treatments-line.php?id=$1 [NC,L]
#rewrite treatments-category
RewriteRule ^/?treatments/category/([0-9]+)$ treatments-category.php?id=$1 [NC,L]
#rewrite product-view
RewriteRule ^/?products/([0-9]+)$ product-view.php?id=$1 [NC,L]
#redirect lang
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/(.*)$ $2.php?lang=$1 [L]
#RewriteRule ^([^\.]+)/?$ index.php?lang=$1 [L]
#remove .php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Upvotes: 2