0

试图将 mod_rewrite 集成到我现有的页面中时,我完全不知所措。目前,我正在从头开始构建一个新网站,并且我有一些不错的干净网址,例如:

http://www.example.nl/nl/example

运行 Cms 的旧站点变得简单,有一些未重写的 url,需要重定向到新页面。这些网址看起来像这样:

http://www.example.nl/index.php?page=cake-and-pie&hl=nl_NL

但更短的版本,如:

http://www.example.nl/index.php?page=cake-and-pie

也工作。

我花了一段时间才弄清楚带参数的 url 不能像我通常做的那样简单地用“重定向 301”重定向。所以我尝试了一些在线 mod_rewrite 生成器,例如thisthis,但这些规则输出的规则只会导致 404 错误,(重定向根本不起作用)。

我的 .htaccess 文件当前如下所示:

RewriteEngine On
RewriteBase /

# remove .php;
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]

# remove index
RewriteRule (.*)/index$ $1/ [R=301]

# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]

# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

旧页面将抓住存在。如何将旧页面重定向到新页面?

谢谢。

编辑

RewriteCond %{QUERY_STRING} =page=pie
RewriteRule ^index\.php$ /nl/? [L,R=301]
RewriteCond %{QUERY_STRING} =page=pie&hl=nl_NL
RewriteRule ^index\.php$ /nl/? [L,R=301]

似乎可以解决问题。这当然是每个 url 的手册,但我只有几个。

4

1 回答 1

0
RewriteEngine On
RewriteBase /
RewriteRule ^(.+)/([^/]+)/?$    index.php?page=$1&hl=$2
RewriteRule ^([^/]+)/?$         index.php?page=$1 [QSA]
于 2011-06-14T14:22:10.580 回答