1

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

http://localhost/sinj.com.hr/administracija?var1=administracija

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

2

4 Answers 4

1

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.

1
  • No problem... I've had my own go-rounds with mod_rewrite... it can be a tricky bastard to nail down sometimes. Oct 15, 2009 at 12:48
0

Hmmmm...what about trying the

DirectoryIndex

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

DirectoryIndex index.php
2
  • 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. Oct 12, 2009 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 Oct 12, 2009 at 10:50
0

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
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .