【问题标题】:How to make a correct htaccess 301 redirect如何进行正确的 htaccess 301 重定向
【发布时间】:2016-03-12 10:38:15
【问题描述】:

我有一个安装在文件夹中的博客。基本上,假设我的博客安装在 www.example.com/folder/ 我想要正确的 301 重定向,如下所示:

example.com -> www.example.com/folder/
www.example.com -> www.example.com/folder/
example.com/index.php -> www.example.com/folder/
www.example.com -> www.example.com/folder/

我有两个 htaccess 文件(一个在 / 中,一个在 /folder 中)。 /文件夹中的那个是由wordpress更新的。

根目录下的htaccess:

RewriteCond %{REQUEST_URI} !^/carte/
RewriteCond %{HTTP_HOST} ^(www\.)?cemaicitesc\.
RewriteRule ^(.*)$ /carte/$1 [L] 

/文件夹中的htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /carte/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /carte/index.php [L]
</IfModule> 

目前,如果我在浏览器中输入 example.com,它会停留在 example.com。

你能帮忙吗?我总是很难使用 htaccess 重定向,所以我更愿意在测试前询问。

谢谢!

【问题讨论】:

    标签: wordpress apache .htaccess redirect mod-rewrite


    【解决方案1】:

    只需尝试更改根目录中的 RewriteRule .htaccess

    RewriteRule ^(.*)$ http://www.example.com/carte/$1 [R=301,L]
    

    其中 www.example.com 是带有 www 前缀的域名

    R=301 进行重定向。在您的示例中,您只需重写 URL。

    【讨论】:

      猜你喜欢
      • 2020-12-17
      • 2018-07-30
      • 2014-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-25
      • 2017-04-15
      • 2015-08-15
      相关资源
      最近更新 更多