Replace part of a URL with .htaccess
15,770
Solution 1
It will depend on your server but you are looking for something along these lines
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com[nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc]
//301 Redirect Entire Directory
RedirectMatch 301 /feeds(.*) /highlights/$1
Solution 2
You can try rewriting the URL using RewriteRule
, like follows:
.htaccess
RewriteEngine on
RewriteRule ^/feeds/details$ /highlights/details/
Hope, that works for you.
You can find more information here.
Related videos on Youtube
Author by
Bernhard Schusser
Updated on September 14, 2022Comments
-
Bernhard Schusser over 1 year
I had to change the name of a subpage and now the problem is that all shared links on Facebook, Twitter, etc. are not working anymore.
That's why I am trying to redirect only a part of a URL with
.htaccess
but I have no solution yet.It should work like this:
www.mydomain.com/feeds/details/ --> www.mydomain.com/highlights/details/
I hope you can help me!
-
Daniel Felipe over 3 yearsIn my case it goes from: example.com/folder/file to example.com/folderfile ... removing the slash.
-
Gabriel Alejandro López López almost 3 yearsIn my case is adding an extra / RedirectMatch 301 /states/(.*) /jobs/$1 turns /states/florida ----> /jobs//florida