1

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

这是新的 htaccess 文件。有问题的问题是让重定向工作。另外,如果您可以简化此文件:

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
4

1 回答 1

0

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

RewriteRule ^index\.php$ %{QUERY_STRING} [C]
RewriteRule page=(.*) /$1? [R=301,L]
于 2012-10-22T09:37:29.757 回答