Reputation: 463
I'm working on my website link architecture. I would like to redirect with my .htaccess already rewritten URL to a new one to keep my incoming links active.
www.website.com/profile-info/ to www.website.com/profile/
This is my actual working .htaccess :
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_URI} /profile-info/?$ [NC]
RewriteRule . models.php [L]
So in order to redirect /profile-info/ to the new URL : /profile/ . I end up with this code. However it redirects /profile/ to /profile-info/.
RewriteCond %{REQUEST_URI} /profile/?$ [NC]
RewriteRule . /profile-info/ [L,R=302]
Upvotes: 0
Views: 131
Reputation: 42885
I think this is what you are looking for:
RewriteEngine On
RewriteMap /
RewriteRule ^/?profile-info/?$ /profile [END,NE,R=301,QSA]
RewriteRule ^/?profile/?$ models.php [L,QSA]
It is a two step strategy:
/profile-info
to the new /profile
/profile
to models.php
You may have to change the RewriteMap
, this obviously depends on your situation.
And a general hint: you should always prefer to place such rules inside the http servers host configuration instead of using .htaccess
style files. Those files are notoriously error prone, hard to debug and they really slow down the server, often without reason. They are only provided for situation where you do not have access to the host configuration (read: really cheap hosting providers) or in case an application needs to write its own rules (which is an obvious security nightmare...).
Upvotes: 1
Reputation: 784908
You can use these 2 rules:
Options +FollowSymlinks -MultiViews
RewriteEngine On
# redirect /profile-info to /profile
RewriteRule ^profile-info/?$ /profile [R=301,NE,L]
# rewrite /profile to /models.php
RewriteRule ^/?profile/?$ models.php [L,NC]
Upvotes: 1