【发布时间】:2014-01-06 15:19:35
【问题描述】:
我的 htaccess 文件中有以下内容,该文件采用如下 URL:www.example.com/Page.php?id=About 并将其转换为 www.example.com/about。唯一的问题是,当我在 htaccess 中设置重定向 301 时,旧 URL 不会重定向到新 URL(我理解这是因为您不应该在基本重定向 301 中传递参数 - 我的基本重定向示例)已在下面尝试过)。
Redirect 301 /Page.php?id=About http://www.example.com/about
问题是新的 URL 不一定只是去掉当前的 id 并将其替换为小写版本。例如,我还想:
Redirect 301 /Page.php?id=Example http://www.example.com/example-page
我想保留重写 URL 的当前功能,但也希望对旧 URL 的任何访问都重定向到新 URL(即更新 Google 索引)。目前访问 www.example.com/Page.php?id=About 仍然有效,但显示的页面没有内容。
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9\-]+)/?$ Page.php?id=$1
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ Page.php?id=$1&tab=$2
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ Page.php?id=$1&tab=$2&tabid=$3
【问题讨论】:
标签: php apache .htaccess mod-rewrite redirect