htaccess 重定向从 domain.com/index.php?page=about 重定向到 domain.co



我已经升级了一个旧网站,并希望将所有旧页面重定向到新页面。 旧网站使用索引页和查询字符串来服务器相关内容。

这是新的 HTepE 文件。 有问题的问题是使重定向正常工作。 另外,如果您可以蒸汽传输此文件:

Options +FollowSymLinks
Options +Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.domain.co.uk$ [NC]
RewriteRule ^(.*)$ http://domain.co.uk/$1 [R=301,L]
#if its not a directory
RewriteCond %{REQUEST_FILENAME} !-d
#and it has a trailing slash then redirect to URL without slash
RewriteRule ^(.+)/$ /$1 [L,R=301]
#this removes php extention
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [NC,L] 
# stops you accessing url with.php
RewriteCond %{THE_REQUEST} ^[A-Z]+ /([^.? ]+).php
RewriteRule ^([^.]+).php(/.+)?$ /$1%{PATH_INFO} [R=301]
RewriteRule ^news/([^/]*)/([^/]*)$ /news?id=$1&title=$2 [L]
Redirect 301 index?page=about http://domain.co.uk/about
ErrorDocument 404 http://domain.co.uk/404

将 domain.com/index.php?page=about 重定向到 domain.com/about 的适当规则如下

RewriteRule ^index.php$ %{QUERY_STRING} [C]
RewriteRule page=(.*) /$1? [R=301,L]

最新更新