【问题标题】:301 redirect with wildcard in htaccess not working在 htaccess 中使用通配符进行 301 重定向不起作用
【发布时间】:2021-04-15 19:45:33
【问题描述】:

所有流量都将来自

https://oldsite.com/

https://www.newsite.com

我正在为以下内容寻找 301 通配符重定向解决方案

https://oldsite.com/blog/*(the slug)

https://www.newsite.com/blog/*(matching slug)

使用的htaccess文件是:

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

【问题讨论】:

  • 欢迎来到 SO,请在您的问题中分享您的 htaccess 规则文件,谢谢。
  • RewriteBase / RewriteRule 上的 RewriteEngine ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule 。 /index.php [L]

标签: .htaccess mod-rewrite mod-alias


【解决方案1】:

使用您展示的示例,请尝试以下操作。将域重定向保留在 htaccess 文件的顶部,然后保留其他规则。还要确保在测试 URL 之前清除浏览器缓存。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

##Have your domain changes rules here...
RewriteCond %{HTTP_HOST} ^oldsite\.com$ [NC]
RewriteRule ^  https://www.newsite.com%{REQUEST_URI} [NE,R=301,L]

RewriteRule ^index\.php$ - [L]

##Non existing files/directories rewrite rules here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php [L]
</IfModule>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-04
    • 2016-09-07
    • 1970-01-01
    • 2015-11-04
    • 2018-10-03
    • 1970-01-01
    相关资源
    最近更新 更多