I am trying to redirect one domain, including all subdirectories/files to the root of a new domain.
I have this thus far
RewriteCond %{HTTP_HOST} ^oldexample\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.oldexample\.com\.au$
RewriteRule ^/?$ "http\:\/\/newexample\.com\.au\/" [R=301,L]
However this rule seems to include any /directory from the old url
To redirect everything from old domain to the root of new domain, change your rule's pattern to the following
^(.*)$
Related
Is it possible to make a conditional redirect using .htaccess in a way that if somebody access my domain directly (example.com) he will be redirected to a subdomain (subdomain.example.com) or may be to another domain, but if someone accesses it through a particular URL (example.com/magic) he get's redirected to example.com i.e. main domain.
In other words, I wanted my users to access the main domain (example.com) only if they are using example.com/magic.
My htaccess is presently redirecting all users of main domain to a subdomain.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "https\:\/\/sub\.example\.com" [R=301, L]
I couldn't find though, how to put the condition in my htaccess.
You may use this rule to redirect every URI that is not /magic or /magic/ to a sub-domain:
RewriteEngine On
# redirect /magic
RewriteRule ^magic/?$ / [L,NC,R=301]
# redirect anything except /magic
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule !^(magic/?)?$ https://sub.example.com [R=301,L,NE]
I did not find yet an example of the following scenario, which I'm trying to accomplish:
Rewrite ANY parked domain root to a page in a subfolder.
The target filename must be the parked domain root, with the dots removed.
The rewrites are transparent, the root URL will stay the same.
Exluded from this rewrite is the primary domain root.
Example:
anyparkeddomain.com will go to primarydomain.com/foo/anyparkeddomaincom
I came up with the following, but that does not work properly because I think it needs a wildcard to make any domain work for it.
RewriteEngine on
RewriteRule ^(.*)\.([^/]*)\.$ /$1$2 [L,R=301]
RewriteCond %{HTTP_HOST} primarydomain\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /foo/$1 [L]
You had the right idea. After the first rule, try this:
# parked domains (redirect drom www to non-www, or vice-versa should already be done)
RewriteCond %{HTTP_HOST} !=primarydomain.com [NC]
# for root only, serve hidden directory
RewriteRule ^$ foo/%{HTTP_HOST}/ [L,DPI]
# remove dots from hidden directory
RewriteRule ^(foo/[^/.]*)\.([^/]*/)$ $1$2 [N]
The next pass will pick up the index file from that directory, assuming that's what you need.
I need to make multiple domain names show the same page, however one specific domain name NEEDS www. in front of the domain name, and I don't want the other domain names to require www. If I remove the OR the first rule works great, but the second rule should force domain and domain4 to use www. no matter what.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.)?(domain2|domain3)\.(com|info)$ [NC,OR]
RewriteCond %{HTTP_HOST} !^(www\.)(domain|domain4)\.(com|info)$ [NC]
RewriteRule ^(.*)$ "http://%1%2.%3/$1" [R=301,L]
I have two domains, one old and one new. The structure on both of the sites is identical so what I need is to transfer anything after the domain to the new page
http://testurl.com/absolutely/anything/here
to
http://testurl2.com/absolutely/anything/here
ive tried:
RewriteRule ^(.*) http://testurl2.com/$1
but nothing is working :/
what every comes after the main url needs to be sent to the new domain.
Try this .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^testurl.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.testurl.com$
RewriteRule (.*)$ http://testurl2.com/$1 [R=301,L]
[R=301] flag is used to redirect URL by status 301
[L] flag is used to break rule matching for further rules if it matched given rule.
I want my domain without www always displayed, ie the URL is valid: http://miweb.net And besides this domain to point to a subdirectory and not the root directory.
How I can indicate in the htacess both conditions?
You may want to take a look at VirtualHost.
Assuming you are using Apache, this will allow you to redirect URLs with www or other sub-domains to different folders on the server.
I think I've found the solution. Apparently it works:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?myweb.net$
RewriteCond %{REQUEST_URI} !^/myweb/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /myweb/$1
RewriteCond %{HTTP_HOST} ^www\.myweb\.net$
RewriteRule ^/?$ "http\:\/\/myweb\.net\/" [R=301,L]
RewriteRule ^(/)?$ myweb/index.html [L]
If you access from a browser http://www.myweb.net, we automatically redirected to http://myweb.net (no www).
And that domain no longer points to the root directory of hosting "/ www /" if not "/ www / myweb /".