views:

31

answers:

1

Hello

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

A: 

There's two problems there. First, your condition

RewriteCond %{REQUEST_URI} !(administration|sitemap)/(.*)\. [NC]

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

RewriteRule ^([a-zA-Z0-9-]+)/lang:([0-9]+)?$    index.php?t=$1&l=$2 [L]

they would not be ignored for

RewriteRule ^([a-zA-Z0-9-]+)/?$                 index.php?t=$1 

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:

# Don't rewrite and stop processing if any of the following is true
RewriteCond %{REQUEST_URI} ^/(administration|sitemap)/ [NC,OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# 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 
Tim Stone
It doesn't work - it is still redirecting to the 404 error-page :/
Dennis Lauritzen
Or more correctly - it is redirecting to "error/404/" which is made with php-headers! That means, that if the folder/or file which is required doesn't exist, it will redirect to error/404/ :)
Dennis Lauritzen
@Dennis Lauritzen: Hmm...Alright, I'll throw it on my test server in a bit and see what might be going wrong with it.
Tim Stone