简体   繁体   English

PHP获取变量干净的URL htaccess

[英]php get variable clean url htaccess

I have some custom PHP pages I am using with a WordPress site. 我有一些与WordPress网站一起使用的自定义PHP页面。 I'd like to use clean URLs which have a couple of variables via the GET method. 我想使用干净的URL,该URL通过GET方法具有几个变量。 I have searched and tried different variations of my htaccess code in combination with the WordPress htaccess code below without success. 我已经搜索并尝试将我的htaccess代码与下面的WordPress htaccess代码结合使用的不同变体没有成功。

I would like the URL that users browse to and use to be www.thedomain.com/thefolder/details/123456/RES, instead of www.thedomain.com/thefolder/details.php?mls=123456&ret=RES 我希望用户浏览并使用的URL是www.thedomain.com/thefolder/details/123456/RES,而不是www.thedomain.com/thefolder/details.php?mls=123456&ret=RES

I've put my code in the htaccess file in the root directory. 我已经将代码放在根目录下的htaccess文件中。 I have also tried it on its own in a htaccess in the directory where the details.php file is located. 我也已经在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

You can add QSA to the RewriteRule flags: 您可以将QSA添加到RewriteRule标志中:

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

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

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

However, be careful because requesting page_1.html?id=2 will redirect to page.php?id=1&id=2, and (in PHP), $_GET['id'] will be 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