htacces redirect to one specific page depending on .tld AND excluding a specific folder - apache

I can't find the solution to this problem:
I'd like to redirect domain.com and all subdirectories and documents to one specific page: special_info.html
But I want ONLY domain.com to be redirected (NOT domain.de)
AND I want to exclude a specific folder from redirection.
Examples:
domain.com should be redirected to domain.com/special_info.html
domain.de/anything should not be redirected
domain.com/any_directory/any_page.html should be redirected to domain.com/special_info.html as well
but
domain.com/shop should NOT be redirected
Any help is appreciated, Thanks a lot for your time

You can use this rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule !^(shop/|special_info\.html) /special_info.html [L,NC,R]

It can be possible by using domain management console , like godaddy's.( I have done it earlier)
Following link may help for your problem , if you have your domain with godaddy.
http://support.godaddy.com/help/article/422/forwarding-or-masking-your-domain-name
Did you try from following,
http://www.branded3.com/blogs/htaccess-mod_rewrite-ultimate-guide/

Related

Change domain redirect all URLs exactly except one URL that must be redirect to a different URL

Change domain from example.net to example.com.
I must to redirect all URLs exactly except one URL that must be redirected to different URL.
To redirect all URLs exactly (www and non-www) I use:
RewriteEngine On
RewriteCond %{HTTP_HOST} (w*)example\.net$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [L,R=301]
Till here everything is perfect.
But I need one URL from old domain to be redirected to a different URL:
example.net/en to be redirected to example.com/abc instead of example.com/en.
I got the fix here: https://webmasters.stackexchange.com/questions/128426/redirect-all-urls-exactly-except-one-url-that-must-be-redirected-to-a-different/128427#128427
I do not understand why on #StackOverFlow I get negative vote for this question.
I hope to help other users this fix!

.htaccess Redirect all Subdomains to an URL

how can I redirect all of the subdomains to a URL
this is the scenario :
abc.xxx.com goes to abc.xxx.com/index.php?id=abc
www.xxx.com/abc or xxx.com/abc also goes to the same URL: abc.xxx.com/index.php?id=abc
and please bear in mind there is no /abc folder on the website
and the file index.php is the root file of the main domain
I want to keep the abc in the subdomain for SEO purpose.
Thanks in advance.
I think you must first check if URL does not contain "index.php?id=" to prevent infinite loop.
RewriteCond %{REQUEST_URI} !index\.php\?id= [NC]

Point add-on domain to a subfolder and redirect direct access to that subfolder to add-on domain using .htaccess

I have a site example.com/main and another site example2.com.
I have set up an add-on domain for example2.com which shows files in the main subfolder in the example.com domain. What I want is that when users go to example2.com, they REMAIN on example2.com while they see files from example.com/main. So if they access other files like main/contact.php, it shows as example2.com/contact.php.
I have successfully done what I mentioned above in the add-on page of cPanel.
My issue:
I want it so that when users visit example.com/main directly, I want them to be redirected to example2.com and then see the main subfolder. I have had no luck as I keep getting stuck in a loop.
Doing Redirect 301 / http://example2.com/ doesn't work.
Thank you.
You can use:
RewriteCond %{HTTP_HOST} example\.com$ [NC]
RewriteCond %{THE_REQUEST} \s/+main[\s/?] [NC]
RewriteRule ^main(/.*)?$ http://example2.com$1 [NC,R=301,L]

.htaccess or cPanel redirects. Redirect pagename in folder to subdomain/pagename (all folder contents)

I am trying to get a redirect set up for my site. I have three subdomains which I use
1) (www.)mysite.com
2) sub.mysite.com
3) anothersub.mysite.com
I initially didn't use subdomains and had all my pages in a www.mysite.com/*.php format.
I am trying to add a redirect to make all the pages under the /myfolder/ folder redirect to sub.mysite.Com/ (NB sub is the same name on my site as the myfolder folder)
I have tried setting up a redirect through cPanel but all the combinations have resulted in 404 errors when I try them. I have also tried various things in .htaccess which resulted in many 404 errors.
I added a simple redirect in cPanel and get the following
e.g.
www.mysite.com/myfolder/myfolder_mypagename.php
should redirect to
sub.mysite.Com/myfolder_mypagename.php
but instead it redirects to
sub.mysite.com/_mypagename.php (missing out the "myfolder" part of the pagename)
Can you assist me in this please? It's driving me bonkers and my hosting company said it wasn't possible (which I find hard to believe!)
This answer is assuming your are facing the issue that, when creating a subdomain through cpanel and pointing it to the desired directory, some part of the urls get striped.
Create you subdomain through cpanel, and make it point to the root directory (just like www.mysite.com), then use this in your htaccess :
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$
RewriteRule ^myfolder/(.*)$ http://sub.mysite.com/$1 [L,QSA,R=301]
RewriteCond %{HTTP_HOST} ^sub\.mysite\.com$
RewriteRule ^(.*)$ myfolder/$1 [L,QSA]

Apache Rewrite/Redirect different for TLD vs directory

I've migrated the content of a site from one domain to another. I have .htaccess Rewrite set up successfully to redirect any request to the old domain to the same location on the new domain, which is working fine, using the following code:
RewriteEngine On
rewritecond %{http_host} ^roundeltable.com
rewriteRule ^(.*) http://wheelspin.tv/$1 [R=301,L]
However, I want to go a little further. When somebody simply requests the old TLD (http://roundeltable.com/) I want them to be redirected to a specific page within the new domain (http://wheelspin.tv/rt). If they make a request to any other location from the old domain (for example, http://roundeltable.com/about) I want them to be sent to that exact same place at the new domain (http://wheelspin.tv/about) the way they currently are now.
Is this possible? If so, how?
So I've found the solution to this issue, which ended up being provided by somebody from Media Temple's service department. Here's the entire code required in the .htaccess file to make this work:
RewriteEngine On
RewriteRule ^$ http://wheelspin.tv/rt/ [L]
RewriteRule ^(.*)$ http://wheelspin.tv/$1
Obviously substitute whatever domain you want to redirect to in place of mine, but that's the solution for my example. Thanks for the help!
If you want to see all the details on my solution, I have it here: christiaanconover.com/media-temple-service-rocks/