0

我有一些用于 WordPress 网站的自定义 PHP 页面。我想通过 GET 方法使用具有几个变量的干净 URL。我已经搜索并尝试了我的 htaccess 代码的不同变体以及下面的 WordPress htaccess 代码,但没有成功。

我希望用户浏览和使用的 URL 是 www.thedomain.com/thefolder/details/123456/RES,而不是 www.thedomain.com/thefolder/details.php?mls=123456&ret=RES

我已将代码放在根目录的 htaccess 文件中。我也在 details.php 文件所在目录的 htaccess 中自己尝试过。

RewriteEngine On

## WordPress code
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./ /index.php [L]

## my code
RewriteBase /thefolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9]+)$ details.php?mls=$1&ret=$2
RewriteRule ^([a-zA-Z0-9]+)/$ details.php?mls=$1&ret=$2
4

1 回答 1

0

您可以将 QSA 添加到 RewriteRule 标志:

RewriteRule {from-url} {to-url} [L,NC,QSA]

RewriteRule page_([0-9]+)\.html page.php?id=$1 [QSA]

将 page_1.html?a=2 重定向到 page.php?id=1&a=2

但是,请注意,因为请求 page_1.html?id=2 将重定向到 page.php?id=1&id=2,并且(在 PHP 中)$_GET['id'] 将为 2。

于 2013-03-16T06:29:32.003 回答