Ok, so I'm sure you've all heard this problem loads of times, but I have search and searched and not found an example which can directly solve my problem. I am currently re-writing the following http://www.domain.com/?p=variable to http://www.domain.com/variable/ However, if I typed in http://www.domain.com/variable (without the trailing slash) I was shown a nice 404 page. I have now fixed that so that I no longer get a 404 page, but the current solution I have in place creates a canonical URL, since http://www.domain.com/variable and http://www.domain.com/variable/ are two different URLs. Is it possible to redirect the http://www.domain.com/variable URL to http://www.domain.com/variable/ ? My .htaccess is currently as follows for this. Options +FollowSymLinks RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^(.*[^/])/?$ /?p=$1 [L] Thanks in advance, Ronin90.
You could try something like this: RewriteEngine On RewriteRule ^([a-z]+)/?$ index.php?p=$1 Code (markup): Untested, off the top of my head. Jay
Would that be instead of RewriteRule ^(.*[^/])/?$ /?p=$1 [L] or as well as? If possible I'd like to do a 301 from without a trailing slash, to with a trailing slash. http://httpd.apache.org/docs/2.0/misc/rewriteguide.html It's mentioned there under "Trailing Slash Problem", but they only do it with static URLs, not URLs that have already been re-written.
Hello, The suggestion (rules) that I provided would replace all you current rules. If you wanted to do a 301, you'd have to have two rules. The first would capture a slash, and the second would capture it without, then send a HTTP 301 to redirect the user to the right location. Lookup the extra RewriteRules such as R,L. Jay
I tried putting your rule in place, and it didn't work. Do you know how to write the R=301 rule to redirect from without slash to with slash? I currently have... RewriteCond %{HTTP_HOST} ^(www.)?domain\.com$ [NC] RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L] In place, so that if someone types in the domain without a trailing slash, it adds one. I don't know how to translate that to this scenario though.
Just to follow this up with a pure Apache solution, the problem is that your original regex treats two different URLs the same and this is the part that does it: RewriteRule ^(.*[^/])[B][COLOR="Red"]/?[/COLOR][/B]$ /?p=$1 [L] Code (markup): The rule above does the same thing to URLs that have or don't have the trailing slash. What you need to do is split that part out into it's own RewriteRule and put the 301 redirect on that rule. RewriteRule ^(.*[^/])$ /?p=$1 [L] RewriteRule ^(.*[^/])/?$ /$1 [R=301,L] Code (markup):