20

I would like to have an alias and redirect the URL tz433.tld/jobs/ to the page tz433.tld/about-us/jobs/.

This is what I've tried by far; it didn't work:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.tz433\.tld/jobs/$
RewriteRule (.*) http://tz433.tld/about-us/jobs.html [R=301,L]

The problem is, in this root path there are multiple domains, because it is a multisite typo3 installation. So something like "redirect /jobs to /about-us/jobs" isn't working because it should only happen for a specific domain (tz433).

The next specific thing is www.tz433.tld automatically redirects to tz433.tld. So it should also work with www.tz433.tld/jobs/ and tz433.tld/jobs. Both should redirect to tz433.tld/about-us/jobs.html.

How can I achieve that successfully?

nyedidikeke
  • 6,899
  • 7
  • 44
  • 59
emjay
  • 1,491
  • 5
  • 17
  • 35
  • Possible duplicate of [Redirect one url to another url using .htaccess](https://stackoverflow.com/questions/18030491/redirect-one-url-to-another-url-using-htaccess) – Huseyin Yagli Jun 10 '19 at 12:10

2 Answers2

25

If you want the rule to only execute when the domain is "tz433.tld", you need this condition:

RewriteCond %{HTTP_HOST} ^(www\.)?tz433\.tld

And to redirect "jobs/" and "jobs" to "tz433.tld/about-us/jobs.html", you can try one of these:

RewriteRule ^jobs/? /about-us/jobs.html [R=301,L]
# or
RewriteRule ^jobs/? http://tz433.tld/about-us/jobs.html [R=301,L]
  • @5ervant i want to do same but your solution isn't working for me i'm using wordpress though and i want to redirect a url if it has `/for-your-practice/`, can you please tell what could go wrong ? This is what i did `RewriteRule ^for-your-practice/? /product-category/for-your-practice [R=301,L]` – Habib Rehman Nov 02 '16 at 16:56
  • 2
    @HabibRehman To redirect _www.example.com/for-your-practice/_ to _www.example.com/product-category/for-your-practice_ you can use your directive. (Check your other directives if they have conflict to that directive.) To redirect all _www.example.com/for-your-practice/anything_ pages to _www.example.com/product-category/for-your-practice_ you can use `RewriteRule ^for-your-practice/(.*) /product-category/for-your-practice [R=301,L]` – 5ervant - techintel.github.io Nov 03 '16 at 13:28
16

If someone is just interested in simple redirect you can try this:

Redirect /URL URLtoRedirect

e.g

Redirect /old-url https://mywebsite.com/new-url
Iftikhar uddin
  • 3,117
  • 3
  • 29
  • 48