简体   繁体   中英

php get variable clean url htaccess

I have some custom PHP pages I am using with a WordPress site. I'd like to use clean URLs which have a couple of variables via the GET method. I have searched and tried different variations of my htaccess code in combination with the WordPress htaccess code below without success.

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

I've put my code in the htaccess file in the root directory. I have also tried it on its own in a htaccess in the directory where the details.php file is located.

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:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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