[SOLVED] Problem with mod_rewrite
Moderator: General Moderators
-
fastfingertips
- Forum Contributor
- Posts: 242
- Joined: Sun Dec 28, 2003 1:40 am
- Contact:
[SOLVED] Problem with mod_rewrite
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?
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?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
-
fastfingertips
- Forum Contributor
- Posts: 242
- Joined: Sun Dec 28, 2003 1:40 am
- Contact:
I found the solution so if anyone elese needs it:
This will add a trailing slash to URL no matter it's length etc.
Code: Select all
RewriteCond %{REQUEST_URI} !(\.|/$)
RewriteRule (.+) $1/ [R=301,L]- tasteslikepurple
- Forum Commoner
- Posts: 46
- Joined: Thu Jan 26, 2006 3:38 am
- Location: Bath, UK
this is the way i do it:
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/
Code: Select all
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /$1/ [L,R=301]-
fastfingertips
- Forum Contributor
- Posts: 242
- Joined: Sun Dec 28, 2003 1:40 am
- Contact:
-
asgerhallas
- Forum Commoner
- Posts: 80
- Joined: Tue Mar 14, 2006 11:11 am
- Location: Århus, Denmark
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:
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??
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>Does anybody have a clue??
-
asgerhallas
- Forum Commoner
- Posts: 80
- Joined: Tue Mar 14, 2006 11:11 am
- Location: Århus, Denmark
UPDATE: Sometimes (i can't see the pattern) it show the following address after redirect: http://www.test.dk:8080//tester/