繁体   English   中英

PHP获取变量干净的URL htaccess

[英]php get variable clean url htaccess

我有一些与WordPress网站一起使用的自定义PHP页面。 我想使用干净的URL,该URL通过GET方法具有几个变量。 我已经搜索并尝试将我的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

您可以将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。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM