简体   繁体   中英

.htaccess url rewrite - remove .php - add trailing slash - and shorten query strings

I've been working on a CMS recently, and wanted to remove the .php add a trailing slash and remove query strings eg page.php?page=contact to page/contact

So far my .htaccess file looks like this:

# This is a .htaccess file
# Don't edit it.

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php\?page=([^&\s]+)&?
RewriteRule (.*)\.php$ /$1/%1/? [L,R=301]

RewriteRule ^([^/]+)/([^/]+)/$ $1.php?page=$2 [QSA,L]

other then that, I can't figure out how to shorten the query string. I've looked around on and couldn't find any other questions specific to this...

Thank you in advance.

I misunderstood you. I though you just needed to truncate the query string. This would pull the page parameter value from the query string and append it to the URL. ? truncates query string as before.

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php\?page=([^&\s]+)&?
RewriteRule (.*)\.php$ /$1/%1/? [L,R=301]

RewriteRule ^([^/]+)/([^/]+)/$ $1.php?page=$2 [QSA,L]

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