简体   繁体   中英

htaccess 301 redirect with regular expressions

helping a client deploy their new website which has a large number of pages. I recently discovered I could create a rewriterule with a 301 redirect.

We have a large htaccess created for a standard rewriterule from urls of the old site to appear ont he new site, but we need them to turn into 301 redirect tot he new url structure on the website else we will have duplicated content.

For example:

 RewriteEngine On
 RewriteRule ^cs_AI_Adobe_CC_Design_Combo.html$ courses/adobe-design-combo [NC,L]

We want to create this into a 301? we have tried the following which didn't work:

 RewriteEngine On
 RewriteRule ^cs_AI_Adobe_CC_Design_Combo.html$ courses/adobe-design-combo [R=301, L]

Just wondering where I'm going wrong?

We also have larger more complex rules that work as a Rewrite but not a Redirect.

Thanks in advance!

You need to remove the space after the , in your rewrite flags. Apache's pretty dumb about parsing directives and parameters so when it sees that space, it assumes that [R=301, and L] are separate parameters and pukes:

RewriteEngine On
RewriteRule ^cs_AI_Adobe_CC_Design_Combo.html$ courses/adobe-design-combo [R=301,L]

You could also just use mod_alias:

Redirect 301 /cs_AI_Adobe_CC_Design_Combo.html /courses/adobe-design-combo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM