Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect a specific url to another url with .htaccess

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?

like image 948
emjay Avatar asked Aug 05 '15 09:08

emjay


People also ask

How do I redirect one link to another link in htaccess?

Use a 301 redirect . htaccess to point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "example.com" domain.

How do I redirect one URL to another URL?

Add a new URL redirectClick the URL Redirects tab. In the upper right, click Add URL redirect. In the right panel, select the Standard or Flexible redirect type. A standard redirect is used to redirect one URL to another.

What is a 301 .htaccess redirect?

What Is a 301 Redirect? A 301 redirect is a permanent redirect. When a user tries to access an old URL, the server sends their browser the 301-Permanently Moved status code and sends them to another page. This is useful for site owners and users because it means they are directed to the next most relevant page.


2 Answers

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]
like image 176
5ervant - techintel.github.io Avatar answered Oct 07 '22 06:10

5ervant - techintel.github.io


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
like image 28
Iftikhar uddin Avatar answered Oct 07 '22 06:10

Iftikhar uddin