Page 1 of 1
[SOLVED] Problem with mod_rewrite
Posted: Tue Mar 21, 2006 1:33 am
by fastfingertips
Hello
I have some url's that look like:
http://localhost/wap/games/
http://localhost/wap/games/game_name/
This urls are rewrited to:
RewriteRule ^(.*)/(.+[^/])/$ index.php?module=$1&category=$2 [L]
RewriteRule ^(.+[^/])/$ index.php?page=$1 [L]
My problem is that if an user inserts only
http://localhost/wap/games (without that ending /) the apache is trying to look in a directory that not exists or file that not exists. How can i add this (/) at the end of an url if not exists?
Posted: Wed Mar 22, 2006 10:29 am
by RobertGonzalez
I think you can remove it from the rewrite rule (or write your regular expression so that way the URL can have it or not and still get the same result). Just a thought.
Posted: Thu Mar 23, 2006 1:28 am
by fastfingertips
I found the solution so if anyone elese needs it:
Code: Select all
RewriteCond %{REQUEST_URI} !(\.|/$)
RewriteRule (.+) $1/ [R=301,L]
This will add a trailing slash to URL no matter it's length etc.
Posted: Thu Mar 23, 2006 9:31 am
by tasteslikepurple
this is the way i do it:
Code: Select all
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /$1/ [L,R=301]
the top line makes sure that it's not a file, obviously you don't want /images/nav.gif to change to /images/nav.gif/
Posted: Thu Mar 23, 2006 9:35 am
by fastfingertips
Indeed you were right

, i'm saying this because i met the problem and i was thinking to post here

.
This problem has been solved.
Posted: Mon Apr 03, 2006 6:14 pm
by asgerhallas
Can I open this again?
I've been looking for exactly that solution, but now as I want to implement it, I can't make it work.
My setup is a little different, than the above. I have a proxy-server (apache 2.0), that uses ProxyPass to redirect to another apache server (ver 1.3) on the same machine port 8080. I want the trailing slashes to be added automatically as well, but it doesn't work, and I really can't tell why. Mod_rewrite is installed correctly. My vhosts looks like this:
Code: Select all
<VirtualHost *:8080>
SSLDisable
DocumentRoot /web/www.test.dk/www
ServerName www.test.dk
ServerAlias test.dk
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /$1/ [L,R=301]
DirectoryIndex index.html index.htm index.php index.php3 index.phtml
<Directory "/web/www.test.dk/">
Options +IncludesNOEXEC
</Directory>
Code: Select all
<VirtualHost xxx.xxx.xxx.xxx>
ServerName www.test.dk
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
I've been trying fx with
http://www.test.dk/tester, but it tells me there a DNS error. Except from this everything works fine.
Does anybody have a clue??
Posted: Mon Apr 03, 2006 6:17 pm
by asgerhallas
UPDATE: Sometimes (i can't see the pattern) it show the following address after redirect:
http://www.test.dk:8080//tester/