home | list info | list archive | date index | thread index

Re: apache reddirect branch

On 11:19 Sun 08 Jun     , Dianne Skoll via linux wrote:
RewriteEngine  on
RewriteRule "^/oldsetname/(.*)" "/newset/$1" [L,R]

That will work. The quotes aren't strictly necessary, and if this is a permanent redirect I'd force the 301 response (302 is the default, which is a temporary redirect). I'd also add NC if you need a case-insensitive match on the left. If your URLs use anchors (#), add the NE flag to prevent hex escapes of those. Finally, if your site uses query params, use QSA to preserve them. So it would look like this if you need all of those flags:

RewriteEngine  on
RewriteRule ^/oldsetname/(.*) /newset/$1 [L,R=301,NC,NE,QSA]

That rule does assume you always have at least a trailing slash, however (.* can match zero characters) - so if you just want to redirect a request with no trailing path and with or without the trailing slash, add a second rule above the first to handle that case:

RewriteRule ^/oldsetname/?$ /newset [L,R=301,NC]

Then you can change .* (zero or more chars) to .+ (one or more chars) in the second match, since you are now assuming you always have a trailing path. All together:

RewriteEngine  on
RewriteRule ^/oldsetname/?$ /newset [L,R=301,NC]
RewriteRule ^/oldsetname/(.+) /newset/$1 [L,R=301,NC,NE,QSA]

Doug

To unsubscribe send a blank message to linux+unsubscribe [ at ] linux-ottawa [ dot ] org
To get help send a blank message to linux+help [ at ] linux-ottawa [ dot ] org
To visit the archives: https://lists.linux-ottawa.org

message navigation