2013-03-16 65 views
0

我有一些自定义PHP页面,我正在使用一个WordPress站点。我想通过GET方法使用干净的URL,其中有一些变量。我已经搜索并尝试了不同版本的htaccess代码,并结合下面的WordPress htaccess代码,但没有成功。PHP获取变量清洁url htaccess

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

我已将我的代码放入根目录中的htaccess文件中。我也尝试过在detail.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 

回答

0

您可以添加QSA到重写规则标记:

重写规则{从-URL} {到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.

+0

_Will redirect page_1.html?a = 2 ..._ - 你确定'RewriteRule' _redirects_? – ShuklaSannidhya 2013-03-16 06:33:39

+0

测试一下,如果它不起作用,请提供有关您的体验的反馈。这样我们可以解决重定向问题,直到它正常工作 – OmniPotens 2013-03-16 06:37:28

+0

嘿,我想说'RewriteRule'不会重定向,它只是重写url。 – ShuklaSannidhya 2013-03-16 06:38:34