简体   繁体   中英

Rename URL from the htaccess file

I would like to rename, not redirect a number of URL's I have on my website using the .htaccess file:
from http://siteaddress.com/?chapter=1 to http://siteaddress.com/about .

As I'm quite new to dabbling with the .htaccess file and I can't afford to brake anything, how would I be able to achieve this in a safe and simple manor?

Thank you.

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+\?chapter=1\s [NC]
RewriteRule ^ /about? [R=302,L]

RewriteRule ^about/?$ /?chapter=1 [L,NC,QSA]

With above in place now when you try to visit http://site.com/about it will internally forward your request to: http://site.com/?chapter=1 while not changing the URL in the browser (no redirect). When you visit http://site.com/?chapter=1 it will be externally redirected to http://site.com/about .

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