Reputation: 1384
I've got a problem with my mod_rewrite code. I want the rewrite to happen based on 3 rules:
So far I've got the first two working, but I can't seem to get the third one working. This is my code:
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule (.*) index.php [QSA,L]
RewriteCond %{HTTP_HOST} ^fietsnl.nl
RewriteRule (.*) http://www.fietsnl.nl [R=301,L]
RewriteCond %{REQUEST_URI} ^page/([a-zA-Z_]+)$
RewriteRule ^page/([a-zA-Z_]+)$ /page/show/id/$1 [L]
If I request http://www.domain.com/page/pagename, it still rederects to the first rule Can you put me in the right direction on what to change?
Thanks!
Upvotes: 0
Views: 39
Reputation: 2145
The L in
RewriteRule (.*) index.php [QSA,L]
Tells mod_rewrite to stop processing rules so the two below that will never get processed in the case that the file doesn't exist on the server.
I'm not a master at mod_rewrite, but by moving the last rule before the first rule it should fix you're problem.
RewriteEngine on
RewriteCond %{REQUEST_URI} ^page/([a-zA-Z_]+)$
RewriteRule ^page/([a-zA-Z_]+)$ /page/show/id/$1 [L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule (.*) index.php [QSA,L]
RewriteCond %{HTTP_HOST} ^fietsnl.nl
RewriteRule (.*) http://www.fietsnl.nl [R=301,L]
Upvotes: 1
Reputation: 9529
Rules are matched in the order that they appear.
I assume that page/pagename
is not an existing file or directory, so it will match the first rule and no other rules will me processed.
In general, you want to have rules arranged from most specific to least specific, and have redirects typically before rewrites.
A simple fix would be to move the first rule to the end.
Upvotes: 0