Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace part of a URL with .htaccess

Tags:

.htaccess

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!

like image 827
Bernhard Schusser Avatar asked Dec 13 '16 15:12

Bernhard Schusser


2 Answers

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
like image 94
chop62 Avatar answered Oct 09 '22 19:10

chop62


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.

like image 42
Naman Avatar answered Oct 09 '22 19:10

Naman