抓住所有重定向

时间:2018-04-14 14:04:47

标签: .htaccess redirect mod-rewrite

这是htaccess文件。我想添加一个全能301重定向RewriteRule。

这不起作用。有什么想法吗?

RewriteRule ^/(.*)$1 http://www.domain.co.uk/ [R=301,L]

以下是其余的重写。

enter coOptions +SymlinksIfOwnerMatch +MultiViews
RewriteEngine On 
RewriteBase /

### HTTP > HTTPS & non WWW to WWW version
# RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
# RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(\S*)\sHTTP [NC]
RewriteRule ^ http://www.domain.co.uk/%1 [NE,L,R=301]

### index.php & index to root domain
RewriteRule ^index(?:\.php)? http://www.domain.co.uk/ [R=301,L]

### special rewrite rules for shortened urls ##
RewriteRule ^section(?:\.php)?/(.*)$ /s/$1 [R=301,L]
### To remove section page if 1 which is default for most (unless products span more)
RewriteRule ^s\.php/(.*)/1/(.*) /s/$1/$2 [R=301,L]
RewriteRule ^product(?:\.php)?/(.*)$ /p/$1 [R=301,L]
RewriteRule ^article(?:\.php)?/(.*)$ /a/$1 [R=301,L]
RewriteRule ^discount(?:\.php)/(.*)$ /d/$1 [R=301,L]

### Core Jshop .php removal
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)\.php/(.*)$ $1.php?$2 [L,QSA]de here

Redirect 301 /blog http://www.domain.co.uk/a/8/nursing-home-news/

RewriteRule ^/(.*)$1 http://www.domain.co.uk/ [R=301,L] 

1 个答案:

答案 0 :(得分:0)

如果您的重写规则在htaccess文件中,那么您需要从规则的模式中删除前导斜杠,因为RewriteRule的正则表达式与不带/的相对旧路径匹配。

尝试:

RewriteRule ^(.*)$ http://www.domain.co.uk/ [R=301,L]

确保在测试之前清除浏览器缓存。