下面提到的代码在.htaccess中做了什么?

时间:2015-12-14 04:39:11

标签: .htaccess serp

有人可以告诉我以下代码的作用吗?

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example-old.com$
RewriteRule (.*) http://www.example-new.com/$1 [R=301,L]

只有当有人输入example-old.com时它才有用吗?包含文件夹的URL会发生什么情况,例如example-old.com/folder1和example-old.com/folder1/sub1/page1.php

我客户的一个网站已成为一场灾难。以下是.htaccess中的代码和Google搜索页面在打开时,会添加额外的' /'在每个显示可怕页面的URL的末尾。我无法弄清楚代码中的错误在哪里:

Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example-old.com$
RewriteRule (.*) http://www.example-new.com/$1 [R=301,L] 

RewriteCond %{HTTP_HOST} ^www.example-old.com$
RewriteRule (.*) http://www.example-new.com/$1 [R=301,L] 

RewriteCond %{HTTP_HOST} ^example-new.com$
RewriteRule (.*) http://www.example-new.com/$1 [R=301,L] 

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

# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
RewriteCond %{HTTP_HOST} ^example-old\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example-old\.com$
RewriteRule ^2015\/?(.*)$ "http\:\/\/www\.example-old\.com\/$1" [R=301,L]

而不是打开包含网址的页面: -

http://www.example-new.com/folder1/page1.php

它打开:

http://www.example-new.com/folder1/page1.php/

由于安全原因,我使用的是example-old和example-new。请帮忙......!

1 个答案:

答案 0 :(得分:0)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example-old.com$
RewriteRule (.*) http://www.example-new.com/$1 [R=301,L]

这会将 example.com/foo/foobar 永久重定向到 example-new.com/foo/foobar

RewriteCond %{HTTP_HOST} ^example-old.com$
RewriteRule (.*) http://www.example-new.com/$1 [R=301,L]

在php上下文中,您将使用

if(host == "example.com" and Request_uri== "any request")
 {header('location : host/Request_uri',301)
else
{no redirection}