简体   繁体   English

htaccess 301使用正则表达式重定向

[英]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. 最近,我发现我可以使用301重定向创建重写器。

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. 我们从旧站点的URL创建了一个大型htaccess,用于标准重写器,使其出现在新站点上,但是我们需要它们将301重定向到该站点上的新URL结构,否则我们将有重复的内容。

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? 我们想将其创建为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: Apache对于解析指令和参数非常愚蠢,因此当看到该空间时,会假设[R=301,L]是独立的参数和恶作剧:

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

You could also just use mod_alias: 您也可以只使用mod_alias:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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