user1752759
user1752759

Reputation: 643

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.

Upvotes: 0

Views: 786

Answers (1)

anubhava
anubhava

Reputation: 785146

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 .

Upvotes: 2

Related Questions