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

Re: apache reddirect branch

Thanks. I will review this as well.

The site currently has at least 7000 potential routes, so i want to ensure I understand what I'm doing. :) It also has a few other rewrites to promote http to https, and to redirect alias domain names, so I am somewhat timid to make the changes.

But now that I'm in my 70s, its about time I learned apache a little more. :)

I'll get back to you all once its in place.

On 2025-06-08 16:27, Doug Maxwell via linux wrote:
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


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