Redirecting full URL including directories - redirect

I'm migrating to a new website.
I want to be able to redirect everything from the old website to the new website in the following structure.
Example 1:
http://dev.website-old.com/abc/123
to
http://dev.website-new.com/abc/123
Example 2:
http://dev.website-old.com/abc/123/xyz
to
http://dev.website-new.com/abc/123/xyz
How do I accomplish this?

This rewrite redirect all requests (1:1) from dev.website-old.com to dev.website-new.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?dev\.website-old\.com [NC]
RewriteRule (.*) http://dev.website-new.com/$1 [R=301,L]

Related

What should I do to fix redirect in cpanel

Im trying to redirect one of my domain to the other one and added a redirect in cpanel with wild card redirect. It has added a line at the end of .htaccess file
RewriteCond %{HTTP_HOST} ^oldDomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.oldDomain\.com$
RewriteRule ^(.*)$ "https\:\/\/newDomain\.com\/$1" [R=301,L]
but its not working correctly if I go to oldDomain.com/about it will redirect to this page https://newDomain.com/cache/wp-rocket/oldDomain.com/about/index-https.html_gzip
what should I do to fix this issue?
I have tried godaddy forward domain

Redirecting urls ending in index.php to clean url

I have a client with a strange set up. In analytics we are seeing urls getting pageviews that technically dont exist.
Example: website.org/questions/search/blog/2016/07/blog-post-name/index.php
The current ht access file looks like this but all that does is redirect these blog urls to the home page.
# Redirect index.php Requests
# ------------------------------
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
Is there an htaccess code to create redirect:
Example: website.org/questions/search/blog/2016/07/blog-post-name/index.php
to: website.org/questions/search/blog/2016/07/blog-post-name
Thanks

How to make a redirect in .htaccess for pages from different subdomains

I'm not very advanced at programming and I need to make a 301 redirection from one specific subdomain page to another. The tricky part, at least for me, is that the pages are on two different subdomains. So far I've only managed to 301 ALL pages to the target or crashing the whole site.
I've used many, but are currently at:
RewriteCond %{HTTP_HOST} !^spiele.deutschedownloads.de/?DriverScanner/Diverse//download/4770$ [NC]
RewriteRule ^(.*)$ http://programme.deutschedownloads.de/?DriverScanner/Drivers/Werkzeuge-Diverse/download/4413 [L,R=301]
What I want to do is simply to 301 redirect
spiele.deutschedownloads.de/?DriverScanner/Diverse//download/4770
To
http://programme.deutschedownloads.de/?DriverScanner/Drivers/Werkzeuge-Diverse/download/4413
Any help is most appreciated!
This should work:
RewriteCond %{HTTP_HOST} ^spiele\.deutschedownloads\.de$ [NC]
RewriteCond %{QUERY_STRING} ^DriverScanner/Diverse//?download/4770/?$ [NC]
RewriteRule ^ http://programme.deutschedownloads.de/?DriverScanner/Drivers/Werkzeuge-Diverse/download/4413 [R=301,L]
First condition matches the domain in case they are both on the same root folder.
Second condition matches the query string.
If both conditions are OK it redirects.

redirecting just a single non-www homepage to www version, without redirecting any other pages

I need to redirect the non-www version of just a single page, the homepage, to www.
I want to leave the rest of the site alone. Due to a need to keep a specific page non www.
So if i try a rewrite rule of
/index.html http://www.example.com/
I get a infinite redirect type error.
There's probably a way to achieve what you want, although I must say that this has a bit of a "smell" to it. It sounds like you are trying to treat a single symptom rather than fix a problem (which, admittedly might be beyond your control). Is it possible that your organization needs to setup a domain pointer so that www.example.com and examples.com are the exact same thing?
So you want
http://example.com/ to go to http://www.example.com/,
but you want
http://example.com/index.html,
http://example.com/otherstuff, and
http://example.com/subdir/path/file.php
to stay the same?
For Apache:
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^/$ http://www.example.com/ [R=301,L]
If you want any non-www subdomain on the site to get redirected to the www version:
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^/$ http://www.%{HTTP_HOST}/ [R=301,L]
If you want to redirect everything except a specific page:
RewriteCond %{REQUEST_URI} !^/subdir/path/file.php$
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

How do I use .htaccess to force www. while using Zend Framework

I want to force a www. prefix on my website by using a .htaccess 301 redirect. I am currently trying:
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
Which normally works, but I am using Zend Framework which causes all requests to be redirected back to http://www.mysite.com/index.php regardless of the initial request.
For example...
http://mysite.com/blog,
http://mysite.com/contact,
http://mysite.com/blog/this-is-my-article,
Will all be redirected to http://www.mysite.com/index.php
However, if I initially request a specific file, such as...
http://mysite.com/some-file.htm
The redirect works properly, redirecting to http://www.mysite.com/some-file.htm
In first time, don't forget to enable the rewriting ("RewriteEngine on").
The last line is important if you use Zend Framework.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
RewriteRule !\.(pdf|php|js|ico|txt|gif|jpg|png|css|rss|zip|tar\.gz)$ index.php
Now the url...
http://mysite.com/some-file.htm
... redirect to http://www.mysite.com/some-file.htm but use the index.php
Don't forget to ignore sub-domains when re-directing to www.
http://www.theblogaholic.com/2011/01/16/force-www-using-htaccess-except-for-subdomains/