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

时间:2012-10-07 16:48:48

标签: .htaccess query-string

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

这是新的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

1 个答案:

答案 0 :(得分:0)

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

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