Forum Moderators: phranque

Message Too Old, No Replies

.htaccess trailing slash troubles

.htaccess trailing slash

         

etono

7:22 pm on Jun 27, 2006 (gmt 0)

10+ Year Member



Hello, first time poster. I was hoping that someone may be able to help me. I have read the mod_rewrite apache docs as well as the library on Webmaster World, but unfortunatly I am still having trouble. I am rewriting the url to send requests such as [domain.com...] to [domain.com...] Everything works great except for requests without the trailing slash. Here is my current .htaccess file:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([^/]+)/$ /profile.php?name=$1 [L]

That makes it work if a slash is added at the end, but I do not know how to get it to work without the slash. I have tried:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([^/]+)/?$ /profile.php?name=$1 [L]

This gives me a 500 error. If anyone has any ideas or can point me to a place to find more information it would be greatly appreciated.

Thank You Very Much!

jdMorgan

9:22 pm on Jun 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is in your server error log when you get the 500-erver Error? The information contained there will often tell you exactly what the problem is.

I'll hazard a guess tht by using a non-specific pattern which matches the substitution URL, you have created an 'infinite' rewrite loop. This can be prevented with a simple exclusion that prevents profile.php itself from being rewritten to profile.php:


Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^profile\.php$
RewriteRule ^([^/]+)/?$ /profile.php?name=$1 [L]

Jim

etono

9:45 pm on Jun 27, 2006 (gmt 0)

10+ Year Member



Thank you JDMorgan.

That solved my problem, thank you so much. I did try a rewrite condition, but was off as I was trying:


RewriteCond %{REQUEST_URI}!^profile.php

Cheers

jdMorgan

10:09 pm on Jun 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Due to an oddity of mod_rewrite in a per-directory (.htaccess) context, RewriteRule patterns don't 'see' the leading slash, but it is always present in the %{REQUEST_URI} variable. So,

RewriteCond %{REQUEST_URI} [b]!^/p[/b]rofile.php

would have worked.

Jim

etono

10:12 pm on Jun 27, 2006 (gmt 0)

10+ Year Member



I was sooo close... Thank you again Jim!