I have these htaccess-rules:
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.de\/subpage$ [NC]
RewriteRule ^(.*)$ http://www.domain.de/subpage.html/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?subdomain\.domain\.de$ [NC]
RewriteRule ^(.*)$ http://www.domain.de/subpage.htm/$1 [R=301,L]
I don't get it. Usually htaccess-redirects are no problem, but this here drives me crazy.
When I open mydomain.de/subpage it tries to open the folder (or throws an 404 for not existing resource). Instead I want my htaccess-rule to trigger. What am I missing?
Okay, got it. Starkeen gave me a direction. Had to use variatons of condition-types: this is my working result:
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.de(/)?$ [NC]
RewriteCond %{REQUEST_URI} subpage
RewriteRule ^(.*)$ http://www.mydomain.de/new_page_html [R=301,L]
Related
I want to open subdomain as folder, for ex: http://sms-rassilka-cityname.sitename.ru open like http://sitename.ru/cities/barnaul/ (real folder with files)
I used this rules for all cities:
RewriteCond %{HTTP_HOST} ^(www\.)?sms-rassilka-cityname\.sitename\.ru$ [NC]
RewriteCond %{REQUEST_URI} !^/cities/cityname/ [NC]
RewriteRule ^(.*)$ /cities/cityname/$1 [L,QSA]
But when I change this for universal rule
RewriteCond %{HTTP_HOST} sms-rassilka-([a-z]+)\.sitename\.ru$ [NC]
RewriteCond %{REQUEST_URI} !^/cities/%1/ [NC]
RewriteRule ^(.*)$ /cities/%1/$1 [L,QSA]
server fall down for error 500: Internal Server Error.
2d line don't gete paremetr, but in 3d it get.
What's wrong in my rules?
Try your rules this way.
RewriteCond %{HTTP_HOST} ^sms-rassilka-([a-z]+)\.example\.ru [NC]
RewriteRule ^((?!cities/.*).*)$ /cities/%1/$1 [L,QSA]
Let's say may main domain is www.mysite.com and that I'm using the following rewrite in my hataccess
RewriteCond %{HTTP_HOST} !^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
All good so far! However, I also need other domains to redirect to specific pages on the site. For example, if somebody types www.mysite.nl they will be redirected to www.mysite.com/neatherlands. The issue is when I pop the below into my htaccess file I get a server error. I think this is because of the final rewrite. It's a pretty mad set-up
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.nl$ [NC]
Rewriterule ^(.*)$ http://www.mysite.com/netherlands/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.be$ [NC]
Rewriterule ^(.*)$ http://www.mysite.com/belgium/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.co.\uk$ [NC]
Rewriterule ^(.*)$ http://www.mysite.com/$1 [R=301,L]
Any suggestions about what to do?
I have 4 domain which I want 3 of them redirect to last one. I already used some htaccess rules and they are working great,
RewriteEngine On
RewriteCond %{HTTP_HOST} ^first.com$ [NC]
RewriteRule ^(.*) http://www.forth.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.first.com [NC]
RewriteRule ^(.*)$ http://www.forth.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^second.com [NC]
RewriteRule ^(.*)$ http://www.forth.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.second.com [NC]
RewriteRule ^(.*)$ http://www.forth.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.third.com [NC]
RewriteRule ^(.*)$ http://www.forth.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^third.com [NC]
RewriteRule ^(.*)$ http://www.forth.com/$1 [L,R=301]
the only problem is when I enter "www.first.com/about" it does not shows "www.forth.com/about" just shows the same thing . all the domain are forwarded to forth.com and they do not have hosting so I cannot put htaccess file for those other domains , please guide. would be appreciated.
This is most likely what is happening, at least on my test cases this fix handles it.
Instead of using [L,R=301] reverse the order and do [R=301,L]. The L means Last and it ends cycle on evaluating what to do at that point. I've always used [R=301,L] as are all the examples that I could find anywhere. Potentially your apache may be hitting that L and immediately pass back the new string to the URL parser and isn't sending it as a 301 Redirect as it didn't get that far.
Also on the first.com snippit above you left out the $ on the ^(.*) - only for that line though, not sure if this was a typo or if it's missing in your actual .htaccess file.
Otherwise, you could tidy it up a bit by using:
RewriteCond %{HTTP_HOST} ^((www.)?)first.com [NC,OR]
RewriteCond %{HTTP_HOST} ^((www.)?)second.com [NC,OR]
RewriteCond %{HTTP_HOST} ^((www.)?)third.com [NC]
RewriteRule ^(.*)$ http://www.forth.com/$1 [R=301,L]
I have the following rules in my .htaccess
rewritecond %{http_host} ^oldname.com [nc]
RewriteRule ^(.*)$ http://www.newname.com [r=301,nc]
rewritecond %{http_host} ^www.oldname.com [nc]
rewriterule ^(.*)$ http://www.newname.com [r=301,nc]
I am wondering how to merge does 2 rules in one. Beside that I would like to redirect if user comes to: www.oldname.com/?action=whatever to newname as well...
Thanks for response!
rewritecond %{http_host} ^(www\.)?oldname.com [nc]
RewriteRule ^(.*)$ http://www.newname.com [r=301,nc]
change the above code to that
rewritecond %{http_host} ^(www\.)?oldname.com [nc]
RewriteRule ^(.*)$ http://www.newname.com/$1 [r=301,nc]
If that not work tell me to give you another solution.
Ok folks, I'm at a loss.
RewriteCond %{HTTP_HOST} ^domain.nl$
RewriteRule ^(.*)$ poker/$1 [L]
Throws me a 500 error. If I remove the redirect and go to /poker/ manually it works. If I use this:
RewriteCond %{HTTP_HOST} ^domain.nl$
RewriteRule ^$ poker/ [L]
The front page is shown (but the css not, because obviously anything after the / is not redirected.
What could cause this (.*) to break?
Before this rule is just this to remove www:
RewriteCond %{HTTP_HOST} ^www\.([a-z-]+)\.([a-z]{2,3})
RewriteRule ^(.*)$ http://%1.%2/$1 [R=301,L]
After it is nothing that could interfere.
It was so easy.
RewriteCond %{HTTP_HOST} ^domain.nl$
RewriteRule ^(.*)$ poker/$1 [L]
Gives an infinite loop. I just had to add:
RewriteCond %{HTTP_HOST} ^domain.nl$
RewriteCond %{REQUEST_URI} !^/poker
RewriteRule ^(.*)$ poker/$1 [L]
(or as I just found out, creating an empty .htaccess with just RewriteEngine On in the /poker/ dir did the trick as well).