0

我目前有多个子域的 wordpress 博客。目前永久链接结构是/%year%/%monthnum%/%day%/%postname%/ 我想改变它删除年份月份和日期,只输入postname。如果我现在这样做的问题,现有链接将引发 404 错误,为了避免它我想将当前的永久链接结构重定向到新的永久链接结构

例如我有 url http://subdomain1.mydomain.com/2012/07/30/my-post-name/然后我希望它被重定向到http://subdomain1.mydomain.com/my-post-name /

RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://subdomain1.mydomain.com/$4

上述正则表达式的问题是将每个子域重定向到 subdomain1.mydomain.com,我想要类似的东西

 RedirectMatch 301 ^subdomain1.domain.com/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://subdomain1.domain.com/$4     
 RedirectMatch 301 ^subdomain2.domain.com/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://subdomain2.domain.com/$4     

上面的东西不起作用。

你能让我更正正则表达式吗?如果需要,我准备为每个子域添加一行 .htaccess

4

1 回答 1

0

Solved it by removing the domain name

RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ /$4

It solves my current requirement, but what if i wanted to some subdomains to redirect and some not to in the future. Can anyone provide a better solution.

tried the below one too but it did not work for me

RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$
RewriteRule ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://subdomain.domain.com/$4 [R=301,L]
于 2012-08-03T15:45:17.870 回答