I am having some troubles with my script..
when I access http://www.domain.com/this-is-a-topic I want it to redirect to http://www.domain.com/index.php?t=this-is-a-topic… BUT when it says “administration”, “sitemap” or some other things, I want it to look either another rewrite condition or simply just get http://www.domain.com/administration/
Here is my code:
RewriteCond %{REQUEST_URI} !(administration|sitemap)/(.*)\. [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Dync links
RewriteRule ^([a-zA-Z0-9-]+)/lang:([0-9]+)?$ index.php?t=$1&l=$2 [L]
RewriteRule ^lang:([0-9]+)?$ index.php?l=$1 [L]
RewriteRule ^sitemap/?$ index.php?sitemap=sitemap [L]
RewriteRule ^error/([0-9]+)?$ index.php?error=$1
RewriteRule ^([a-zA-Z0-9-]+)/?$ index.php?t=$1
The problem is, that when I write /administration/ it goes to http://www.domain.com/index.php?t=/administration/ instead of going to http://www.domain.com/administration/index.php
There’s two problems there. First, your condition
will always be true, because the value of
%{REQUEST_URI}always has a leading forward slash (so the pattern will always not match). You also likely don’t want to look for that dot for the cases where you browse to the sitemap and administration folders directly.Secondly, the conditions only apply to the very next rule, so while the folders would be ignored for the rule
they would not be ignored for
There’s several ways to fix this, but the easiest might be to just ignore the rest of the rules in the case where any of your conditions match upfront, like this: