简体   繁体   中英

Remove the query string from url using htaccess

I need some help with htaccess. Would you be so kind to assist a little bit? I have a URL like this

https://example.com/index.php?p=application-intelligence

[or]

https://example.com/?p=application-intelligence

Basically the index.php is passed some parameter 'home' to know which page to load ie home.php So I've tried to follow your post on your blog but with not much luck.

So I'd like the final code to be

https://example.com/application-intelligence

Here's my code.

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?p=$1

Also for the https://example.com?p=home

I'd like it to be just

https://example.com

This is what i have in my apache virtual host conf file:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

You may use these rules:

RewriteEngine on

# handle /?p=home
RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?p=home\s [NC]
RewriteRule ^ /? [R=301,L,NE]

# handle /?p=<something>
RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?p=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?p=$1 [L,QSA]

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