9

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!

1

3 Answers 3

11

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
Sign up to request clarification or add additional context in comments.

2 Comments

In my case it goes from: example.com/folder/file to example.com/folderfile ... removing the slash.
In my case is adding an extra / RedirectMatch 301 /states/(.*) /jobs/$1 turns /states/florida ----> /jobs//florida
3

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.

Comments

1

I took your tip and adjusted my reality.

My problem:

https://example.com/contact/example.com

My solution:

RedirectMatch 301 (.*)/example.com(.*) $1/$2

After solution, redirect:

https://example.com/contact/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.