htacces redirect with subdomain-change - .htaccess

After namechange of an navigation sub-topic we have to redirect all pages to the new subdomain:
Old: /max/sport/es-wird-besser
New: /max/geschichten/es-wird-besser
redirectMatch 301 ^/max/sport$ /max/geschichten$1
Unfortunately it doesnt work proberly.

Try with below, we are using matching groups.
RedirectMatch 301 ^/max/sport/(.*)$ /max/geschichten/$1

Related

Change Directory with Wildcard Redirect using RedirectMatch not working

I am trying to use a RedirectMatch to redirect all files under one directory to the main directory:
RedirectMatch 301 ^/question/.*$ https://www.sample.com/
So that if I have a URL like www.sample.com/question/what-day-is-it
It will automatically redirect to www.sample.com/what-day-is-it
The problem is when I put in the RedirectMatch like above, it redirects all URLs to the homepage: www.sample.com/question/what-day-is-it to www.sample.com
If anyone else had the same problem, a simple Redirect 301 /question / did the trick.

301 Redirect just first Subfolder

I have a 301 Redirect from one page to another
REDIRECT 301 /cloud-computing /it-infrastructure/cloud-computing
Now when i use this redirect also the subpages of cloud-computing are affected by this 301 redirect, but they have to be redirected somewhere else. How can i just redirect the folder and not the subpages?
You should be using RedirectMatch for precise matching using regex:
RedirectMatch 301 ^/cloud-computing/?$ /it-infrastructure/cloud-computing
Clear your browser cache before testing the change.

HTACCESS rewrite, select after a specific character

I'm trying to create a 301 redirect for some old URLs. An example of an old URL:
http://www.example.com/forum/news/555-subject-test
I want to redirect this to:
http://www.example.com/news/subject-test
I have this:
RedirectMatch 301 /forum/news/(.*)-(.*) /news/$1
However this redirects it to http://www.example.com/forum/news/test
Any ideas how I can fix this? Thank you!
You can use:
RedirectMatch 301 ^/forum/news/[0-9]+-(.+)$ /news/$1
rather than:
RedirectMatch 301 /forum/news/(.*)-(.*) /news/$1

Very Simple 301 Redirects First line only working in htaccess

Have searched high and low for an answer - 301 redirects seem a common issue on here but after much reading I'm stumped!
I have a simple htaccess file with three 301 redirects in:
redirect 301 example1.htm http://www.example.co.uk/newexample1.htm
redirect 301 example2.htm http://www.example.co.uk/newexample2.htm
redirect 301 example3.htm http://www.example.co.uk/newexample3.htm
However, only the first 301 redirect is working. Subsequent redirects aren't being followed.
The site doesn't have a CMS - is all just pure css/html.
Any suggestions?
Try these rules with RedirectMatch to target specific page with regex:
RedirectMatch 301 ^/example1\.htm$ http://www.example.co.uk/newexample1.htm
RedirectMatch 301 ^/example2\.htm$ http://www.example.co.uk/newexample2.htm
RedirectMatch 301 ^/example3\.htm$ http://www.example.co.uk/newexample3.htm

Order of 301 Redirects?

I am curious if someone could educate me to better understand why the following does not work based on the order.
When I have the redirect for /contact first the location pages fail to redirect properly.
Redirect 301 /contact http://www.example.com/contact-us
Redirect 301 /index.php/contact/location1 http://www.example.com/contact-us/location1
Redirect 301 /index.php/contact/location2 http://www.example.com/contact-us/location1
When I have it after the locations, they work normally. Why is this?
Redirect 301 /index.php/contact/location1 http://www.example.com/contact-us/location1
Redirect 301 /index.php/contact/location2 http://www.example.com/contact-us/location1
Redirect 301 /contact http://www.example.com/contact-us
It is because other 2 URLs also have /contact in them.
It is always better to use RedirectMatchdirective that with capability to use regex so that you can match exactly what you need.
Using RedirectMatchdirective following will also work:
RedirectMatch 301 ^/contact/?$ http://www.example.com/contact-us
RedirectMatch 301 ^/index\.php/contact/location1/?$ http://www.example.com/contact-us/location1
RedirectMatch 301 ^/index\.php/contact/location2/?$ http://www.example.com/contact-us/location1

Resources