I know there is a lot of questions on here about this... but right now I feel like a deer stunned by oncoming headlights... I just don't know where to start and which option to choose.
My requirements are simple.
User goes to http://application.domain.com or http://www.application.domain.com and the real location of these files is http://www.domain.com/application
Obviously this needs to be done using wildcards so that any domain (even if it doesn't exist) triggers the rewrite.
I hope this makes sense to someone
EDIT:
I should also mention I have added the wildcard A record to my DNS entries in Cpanel *.domain.com
Thanks
Tim
I posted this question onto serverfault.com and icyrock solved it. Incase anyone else is wondering the answer given is here:
https://serverfault.com/questions/203780/troubleshooting-a-htaccess-wildcard-subdomain-rewrite/203804#203804
Tim
Simplest way in .htaccess would be to put the following in an htaccess file as high up in the hierarchy as possible.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.application\.* [OR]
RewriteCond %{HTTP_HOST} ^application\.* [NC]
RewriteRule .* http://www.domain.com/application [L]
Related
I have a brainteaser and need help from people smarter than me. I have a shared hosting account. I'd like to 301 forward the root URL (say, domain.org) to a new URL. I also want one folder (/blog/) to be left alone (not forwarded). I was able to find an example of this here, and I put together this potential scenario for doing that:
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule ^(.*)$ http://newdomain.org/$1 [L,R=301]
I believe that this should be OK, but here's the trick: I have add-on domains in this hosting, and if I use the above, I'm pretty sure that I will forward every one of them to newdomain.org, not just domain.org. I did some testing using more specific text strings in the first spot following RewriteRule, but I can't seem to get the syntax without blowing up my site and getting a 500.
Any ideas would be greatly appreciated!
Thanks, Dave
Try adding another condition:
RewriteCond %{HTTP_HOST} ^domain\.org$ [NC]
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule ^(.*)$ http://newdomain.org/$1 [L,R=301]
Where domain.org is the domain that you want everything to be redirected to newdomain.org, except /blog/.
Sorry to be the asker of yet another tedious mod_rewrite question but after having made no progress in the last few hours, I thought it was time to ask ;)
I am trying to redirect URLs like these:
/some/thing?a=1 --> http://something-else.com/blah
/some/thing?a=1&b=whatever --> http://something-else.com/blah2
No need to keep the param values - the new URL will be hard-coded for each one I have to be redirected.
Have tried a few different things from other posts but with no joy so I am back to square one so any suggestions would be most welcome.
Thanks! :)
You can use the following rule-set:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^a=1$
RewriteRule /some/thing http://something-else.com/blah [L]
This is indeed quite a common question, and people tend to overlook the QUERY_STRING variable. Have you tried it before?
This is what I used in the end:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(a=1&b=whatever)$
RewriteRule /some/thing http://something-else.com/blah2 [L,R=301]
I was adding the rules at the bottom rather than directly below the "RewriteEngine On" which was preventing it from working.
This solution does still append the params to http://something-else.com/blah2 which isn't exactly what I wanted but it will do.
I´m not feeling good asking this question (there are already a lot of good answers + tuts here). But after hours of trial I need help.
THE PROBLEM:
Due to an CMS Migration URLs have changed a bit. Old URLs are safed in a Database. Before I change ever link in Mysql I thought it would be much faster to do an .htaccess rewrite of those links. What I want is:
change
index.php/aktuelles?id=369:netzwerk-forst-und-holz-unterfranken-startet-ab-12-2012-&catid=1:news
to
index.php/369:netzwerk-forst-und-holz-unterfranken-startet-ab-12-2012-&catid=1:news
means simple cut the
aktuelles?id=
of the URL. Here my trials:
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^aktuelles\?id\=$ $1 [R=301]
#RewriteRule (.*)/index.php/aktuelles?id=(.*) $1/$2 [R=301]
Thanks a lot for your help,
kind regards,
tony
Here you go. This should cut out the aktuelles?id= from the provided URL:
RewriteCond %{QUERY_STRING} ^id=([^]+]+)$
RewriteRule ^([^/]*)/(aktuelles)$ $1/%1? [L, R=301]
It's untested - please tell me if this worked for you.
I know nothing about code sadly but i'm hoping that you can help. I've tried asking my web designer but he claims he doesn't know what a 301 redirect is and have noticed his own site has canonicalization issues.
I need to redirect the 3 urls below to www.mydomain.co.uk
www.mydomain.co.uk/index.html
mydomain.co.uk/index.html
mydomain.co.uk
I have never used ftp before, but have downloaded filezilla tonight so i can try fix this and have made a .htaccess file as my site didnt seem to have one.
I have browsed (almost) the whole internet looking for answers to this solution and have tried some codes suggested in previous posts on here but they didn't seem to do anything.
If you need to know, i think my server is apache.
I hope your site isn't built using HTML.. However, using your .htaccess you could try:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mydomain\.co\.uk [NC]
RewriteRule ^(.*)$ http://www.mydomain.co.uk/ [R=301,L]
This should be sufficient enough to force the www If you need to force the index.html you would do:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mydomain\.co\.uk [NC]
RewriteRule ^(.*)$ http://www.mydomain.co.uk/$1 [R=301,L]
It's been a while, but both of these should sufficient to do what you want...
I think it's time to find a new developer, because the one you have sounds like a complete idiot.
Apologies if this is answered elsewhere. I had a search for this on here, but I'm quite confused so I'm not 100% what to search for in the first place.
I have a Wordpress site which is at exampledomain.com. I also own exampledomain.co.uk, and I have put in the .htaccess file the follow lines:
RewriteCond %{http_host} ^exampledomain.co.uk [nc]
RewriteRule ^(.*)$ http://exampledomain.com/$1 [r=301,nc]
These work fine in terms of changing exampledomain.co.uk to exampledomain.com, but the moment I add in something after the exampledomain.co.uk (i.e. exampledomain.co.uk/page1) the .htaccess file doesn't change it so it tries to load.
Is there something I can add to the .htaccess file which will sort this, so that, for example, if I were to type exampledomain.co.uk/page1 it would redirect to exampledomain.com/page1 ?
Thanks,
Charlie
P.S. Apologise for the weirdly parsed example links, but as a new user it won't let me include more than two hyperlinks.
Why not simply do
RedirectPermanent / http://exampledomain.com
in the co.uk's config instead? mod_rewrite is very handy, but for a simple domain redirector, it's major overkill.
comment followup:
I'd go for something like this:
RewriteCond %{HTTP_HOST} exampledomain.co.uk$ [NC]
RewriteRule (.*) http://exampledomain.com/$1 [R=301,L]