RewriteRule and Trailing Slashes
July 15, 2005 6:17 AM Subscribe
How do I write a RewriteRule for an .htaccess file that includes if the user does (or doesn't) use a trailing slash?
And I think I need to make it a permanent redirect right? Or use some kind of [QSA] attribute?
RewriteRule ^/virtual-directory/(Not sure what goes here) /actual-place-to-go
And I think I need to make it a permanent redirect right? Or use some kind of [QSA] attribute?
I put a:
?/?
at the end of the source (as opposed to the target) to allow an optional trailing slash.
posted by waldo at 9:38 AM on July 15, 2005
?/?
at the end of the source (as opposed to the target) to allow an optional trailing slash.
posted by waldo at 9:38 AM on July 15, 2005
This thread is closed to new comments.
RewriteRule ^virtual-directory/* /actual-place-to-go [L,R=301]
First, if this is in an .htaccess file, you don't want the leading forward slash (^/). If this is going in the http.conf, you do want this. If you have the power, always include mod_rewrite rules in the http.conf file. See docs for reasons why.
The * special character indicates "include the previous character 0 or more times".
The [L] says "make this the last redirect", which you probably want and will save your server a little extra work.
As to what kind of Redirect it should be (perm, temp), that depends on what you're using it for. If you do want this to be a permanant redirect (meaning, among other things, the URL in the browser will change to /actual-place-to-go), the R=301 takes care of that.
posted by alana at 6:38 AM on July 15, 2005