Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Let me start immediately with my problem:

Options +FollowSymLinks
RewriteEngine On

RewriteBase / 
RewriteRule ^([a-zA-Z0-9_-]+)$ sinj.com.hr/index.php?var1=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ sinj.com.hr/index.php?var1=$1&var2=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ sinj.com.hr/index.php?var1=$1&var2=$2&var3=$3 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ sinj.com.hr/index.php?var1=$1&var2=$2&var3=$3&var4=$4 [L]

RewriteRule ^([a-zA-Z0-9_-]+)/$ sinj.com.hr/$1 [R=301,L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ sinj.com.hr/$1/$2 [R=301,L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ sinj.com.hr/$1/$2/$3 [R=301,L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ sinj.com.hr/$1/$2/$3/$4 [R=301,L]

There is folder sinj.com.hr/administracija and when I try to access http://localhost/sinj.com.hr/administracija I am redirected to


What I would like is when user enters http://localhost/sinj.com.hr/administracija that he is redirected to http://localhost/sinj.com.hr/administracija/index.php. I tried to do this with header("Location:... ") but it always redirects me to http://localhost/sinj.com.hr/administracija?var1=administracija. If folder administracija is renamed then header() function works. Any ideas how to solve this?

Thanks, Ile

share|improve this question
What's in your httpd.conf file? –  random Oct 12 '09 at 10:12
add comment

4 Answers

up vote 1 down vote accepted

Testing on my own Apache configuration I created the directory DOCUMENT_ROOT/sinj.com.hr and placed the .htaccess file in there along with a simple index.php file that just dumped the $_REQUEST contents back to me.

Here is the .htaccess I used:

Options +FollowSymLinks
RewriteEngine On

RewriteBase /sinj.com.hr
RewriteCond %{REQUEST_URI} !^/sinj.com.hr/index.php
RewriteRule ^([^/]+)$ index.php?var1=$1 [R,L,QSA]
RewriteRule ^([^/]+)/([^/]+)$ index.php?var1=$1&var2=$2 [R,L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ index.php?var1=$1&var2=$2&var3=$3 [R,L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ index.php?var1=$1&var2=$2&var3=$3&var4=$4 [R,L,QSA]

The RewriteCond line catches the index.php to keep it from going into a recursive loop. I also gave each RewriteRule the redirect (R) and query string append (QSA) flags in addition to tell them they were the last (L) rule to apply.

I also changed the match grouping to include anything except a slash (/) to simplify the matching.

share|improve this answer
Thank you very much for answering! –  ile Oct 15 '09 at 11:38
No problem... I've had my own go-rounds with mod_rewrite... it can be a tricky bastard to nail down sometimes. –  Jeremy Bouse Oct 15 '09 at 12:48
add comment

Hmmmm...what about trying the


directive in the .htaccess file under the administracija folder? In this case, I'd specifically suggest:

DirectoryIndex index.php
share|improve this answer
It doesn't work. Only when I remove last 4 lines from htaccess then it works... actually I'm still redirected to the same address but this time content is displayed. Also, I don't know how users are going to reach forum because this is going to existing portal and users are used to reach content via specific url which is now not accessible. –  ile Oct 12 '09 at 10:34
I found solution on stackoverflow: RewriteCond %{REQUEST_FILENAME}/index.php -f RewriteRule ^ %{REQUEST_URI}/index.php And it must be places before last 4 lines in above example –  ile Oct 12 '09 at 10:50
add comment

couldnt get text being displayed as code in comment so I'll have to use answer...

RewriteCond %{REQUEST_FILENAME}/index.php -f
RewriteRule ^ %{REQUEST_URI}/index.php
share|improve this answer
add comment

The following rule is causing the behavior:

RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ sinj.com.hr/index.php?var1=$1&var2=$2 [L]

That is redirecting /sinj.com.hr/administracija to sinj.com.hr/index.php?var1=administracija

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.