.htaccess - 捕获所有重定向

标签 .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] 

最佳答案

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

尝试:

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

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

关于.htaccess - 捕获所有重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49832275/

相关文章:

java - Jersey:如何在不更改地址栏中的 URL 的情况下重定向/转发

.htaccess - 重写本地主机和实时环境的规则

redirect - SSL 域重定向到不相关的 URL?

reactjs - 使用react-aad-msal在 token 过期后重定向身份验证循环

.htaccess - http.conf 将 example.com/foo/bar 重定向到 example.com/foo?id=bar

.htaccess - Mod重写,url变量

.htaccess - 未指定输入文件 - Joomla

php - 将 codeigniter 迁移到另一台服务器

php - .htaccess - 传递 URI 参数而不是目录列表 PHP

php - 在文件夹中使用 .htaccess 隐藏查询字符串