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).
Related
I'm not sure what causes redirect loop here.
RewriteEngine on
This bit removes .html extention
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
This bit force non www
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
this bit supposed to force SSL, but apparently I get redirect loop when add this, but from what I understand this should only trigger if HTTPS is off?
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The solution that worked was:
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{REQUEST_URI} !^/(.well-known)(/|$)
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
It was webfaction shared hosting, so it looks like server variable ${HTTPS} was not correct as #MrWhite pointed out.
Let's say short.com is the short domain and long.com is the long domain
updated:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.long.com
RewriteRule (.*) http://long.com/ [R=301]
RewriteCond %{HTTP_HOST} ^short\.li$ [NC]
RewriteCond %{REQUEST_URI} !^/redirect
RewriteRule ^(.*)$ /redirect?short=$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)short\.li$
RewriteRule ^$ http://long.com/ [L,R=301]
both domains point to that root directory. When I type short.li I end up on long.com/?l=
how did I manage to screw up like that?^^
Try this in your htaccess file :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)short\.com$
RewriteRule ^$ http://www.long.com/ [L,QSA,R=301]
Remove RewriteEngine on if it is already there
I think you might want something along the lines of this:
RewriteEngine on
RewriteCond {REQUEST_URI} !/
RewriteCond {HTTP_HOST} short.com
RewriteRule ^(.*) http://long.com/redirect.php?short=$1 [L,R=301]
RewriteCond {REQUEST_URI} /
RewriteCond {HTTP_HOST} short.com
RewriteRule ^(.*) http://long.com/ [L,R=301]
Not sure if the regex is needed on that last one or not, but something like this should work
I have been trying to put 2 seperate sites in subfoldres and use rewites to load them.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.udstde\.co\.uk
RewriteCond %{HTTP_HOST} test1\.udstde\.co\.uk
RewriteRule (.*) /test1/index.php [L]
RewriteCond %{HTTP_HOST} !^www\.udstde\.co\.uk
RewriteCond %{HTTP_HOST} test2\.udstde\.co\.uk
RewriteRule (.*) /test2/index.php [L]
The problem being the first one works fine but the second one doesn't.
Can anyone see where im going wrong?
I see the problem, in your first set of conditions,
RewriteCond %{HTTP_HOST} !^www\.udstde\.co\.uk
RewriteCond %{HTTP_HOST} test1\.udstde\.co\.uk
whenever test2 comes up, above condition turns true as both conditions turn false. (i guess)
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.udstde\.co\.uk
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).udstde\.co\.uk [NC]
RewriteRule (.*) %1/$1 [L]
I have this code in my .htaccess to handle subdomains (http://foo.mydomain.com)
RewriteCond %{HTTP_HOST} !^www.mydomain.com
RewriteCond %{HTTP_HOST} ([^.]+).mydomain.com [NC]
RewriteRule ^(.*)$ filter.php?type=country&country=%1 [L]
The problem is what do i have to do if for example someone puts a link like this:
http://foo.mydomain.com/bar
i want to redirect this to another page different from the filter.php (say otherpage.php) from the previous code, i tried the next code but it isn't working
RewriteCond %{HTTP_HOST} !^www.mydomain.com
RewriteCond %{HTTP_HOST} ([^.]+).mydomain.com/([^/]+) [NC]
RewriteRule ^(.*)$ otherpage.php?type=country&country=%1 [L]
neither the next one:
RewriteCond %{HTTP_HOST} !^www.mydomain.com
RewriteCond %{HTTP_HOST} ([^.]+).mydomain.com [NC]
RewriteCond %{REQUEST_URI} ^/([^/]+)
RewriteRule ^(.*)$ otherpage.php?pname=$1 [L]
The link is always resolved with the first rule i wrote.
Add a condition to your first group that checks for an empty REQUEST_FILENAME. This will prevent it from matching when there's something other than a bare domain name.
RewriteCond %{HTTP_HOST} !^www.mydomain.com
RewriteCond %{HTTP_HOST} ([^.]+).mydomain.com [NC]
RewriteCond %{REQUEST_FILENAME} ^/?$
RewriteRule ^(.*)$ filter.php?type=country&country=%1 [L]
I have a htaccess which looks like this:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [QSA]
RewriteRule ^$ /naujausios [L,R]
And I'm not sure where to put this:
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
for it to work properly - I tried a few modifications to the keys at the end, without success - I just end up with a 500 response. Thanks for your help!
I had conflicts wherever I put it, but the solution was to put the www bit rewrite at the very top just after RewriteEngine on