301 redirect old pages?

Hi guys, sorry for the wrong forum, there isn’t an apache thread.
l’m trying to use htaccess to 301 redirect a bunch of old pages to a newly improved page. – l have a lot of them and l was wondering if there was a cleaner way of doing this?

Redirect 301 /page1/ /newpage/
Redirect 301 /page1 /newpage/
Redirect 301 /page2/ /newpage/
Redirect 301 /page2 /newpage/
Redirect 301 /page3/ /newpage/
Redirect 301 /page3 /newpage/

Is there something like this l can do?

Redirect 301 (/page3|/page2|page1) /newpage/

Another point to mention, l have each URL listed twice, because it doesn’t seem to work because of the trailing slash on the old page – sometimes it’s there for visitors sometimes it’s not.

Not that I know of and I looked for a long time. Here is the 301 I use. Make sure you use full paths on the new URL

301 permanent redirect about.html to about-us.html

redirect 301 /about.html http://www.mydomain.com/about-us.html

And about the trailing slash. If using full paths doesn’t fix that then implement this. This will add the trailing slash to your domain and folders among other things.



mod_alias’s Redirect can’t use a regex engine so, no, your suggestion won’t work. I’m not an expert in mod_alias but you can lookup RedirectMatch and it just might be able to help you.

mod_alias, because of the regex engine, is slower but far more powerful (it can look at more than the {REQUEST_URI}) so what you’ve done is close to:

RewriteEngine on
RewriteRule (page1|page2|page3)/? newpage [R=301,L]

… but that’s only after you slap yourself silly for allowing trailing /'s on files (that should be reserved for directories).

If you need more information about mod_rewrite, you might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too.



RedirectMatch seems to be designed for situations exactly like this.

RedirectMatch 301 ^/(?:page1|page2|page3)/?$ /newpage/