.htaccess: Transparently adding a name to the request - .htaccess

I've read this tutorial about how to modify your .htaccess in order to server many web2py applications but it doesn't seem to work.
Here is my .htaccess
RewriteEngine On
RewriteRule ^dispatch\.fcgi/ - [L]
RewriteRule ^(.*)$ dispatch.fcgi/$1 [L]
RewriteCond %{HTTP_HOST} =www.moublemouble.com [NC, OR]
RewriteCond %{HTTP_HOST} =moublemouble.com [NC]
RewriteRule ^/(.*) /moublemouble/$1 [PT,L]
All I get is a 500 Internal Error and .htaccess is not my strong point.
Any clues?

It’s either the illegal space in [NC, OR] or you are getting a recursion loop since the substitution /moublemouble/… is also matched by the pattern ^/(.*). So try this:
RewriteCond %{HTTP_HOST} =www.moublemouble.com [NC,OR]
RewriteCond %{HTTP_HOST} =moublemouble.com [NC]
RewriteCond $1 !^moublemouble/
RewriteRule ^/(.*) /moublemouble/$1 [PT,L]
Or more compact:
RewriteCond %{HTTP_HOST} ^(www\.)?moublemouble\.com$ [NC]
RewriteRule !^/moublemouble/ /moublemouble%{REQUEST_URI} [PT,L]

It might be your RewriteCond causing the problem.
I haven't tried it, but you could try...
RewriteCond %{HTTP_HOST} ^www.moublemouble.com [NC, OR]
RewriteCond %{HTTP_HOST} ^moublemouble.com [NC]
RewriteRule ^/(.*) /moublemouble/$1 [L]

Related

SEO, joomla and 2 domains for 2 languages

I’ve been looking around for the answer but I can't seem to find it. This is what I need:
www.domain1.it/en -> www.domain2.com/en
www.domain2.com/it -> www.domain1.it/it
I have tried a lot of possible solutions but no one works
RewriteCond %{HTTP_HOST} www.domain2.com
RewriteCond %{REQUEST_URI} ^/it/ [NC]
RewriteRule .* http://www.domain1.it/it [R=301,L]
It doesn’t work:
RewriteCond %{HTTP_HOST} ^www\.domain2\.com$
RewriteCond %{REQUEST_URI} ^/it/(.*)$
RewriteRule ^(.*)$ http://www.domain1.it/$1 [L,R=301]
It doesn’t work:
RewriteCond %{HTTP_HOST} ^www\.domain2\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/it/(.*)$
RewriteRule ^(.*)$ http://www.domain1.it/$1 [L,R=301]
It doesn’t work:
RewriteCond %{HTTP_HOST} www.domain2.com
RewriteCond %{REQUEST_URI} ^/it/
RewriteRule ^(.*)$ http://www.domain1.it/it/ [R=301,L]
It doesn’t work:
RewriteCond %{HTTP_HOST} ^www\.domain2\.com
RewriteCond %{REQUEST_URI} ^/it/
RewriteRule ^(.*)$ http://www.domain1.it/$1 [R=301,L]
It doesn’t work:
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
RewriteCond $1 !^en/$ [NC]
RewriteRule ^(.*)$ http://www.domain1.it/$1
I actually think some of your attempts would work, but your problem is probably your browser caching redirects making your debugging unreliable.
I think the following redirects are simpler and will do what you want.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain2\.com$ [NC]
RewriteRule ^it(.*) http://www.domain1.it/it$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.domain1\.it$ [NC]
RewriteRule ^en(.*) http://www.domain2.com/en$1 [R=301,L]

ip to domain htaccess not working

i cannot redirect my domain ip to the domain name, i have the following in my htaccess file which im told should work
RewriteCond %{HTTP_HOST} ^37\.61\.233\.81
RewriteRule (.*) http://jpcreativevision.co.uk/$1 [R=301,L]
But thats not working, anyone got any idea why it isnt working? thanks for the help.
Edit
Full htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
RewriteCond %{HTTP_HOST} ^37\.61\.233\.81
RewriteRule (.*) http://jpcreativevision.co.uk/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^jpcreativevision\.co.uk
RewriteRule (.*) http://jpcreativevision.co.uk/$1 [R=301,L]
ErrorDocument 404 http://jpcreativevision.co.uk/404.php
Just tested it via http://htaccess.madewithlove.be/ and it says, that your rule should work as expected.
However, you may try a different order of your rules:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^37\.61\.233\.81
RewriteRule (.*) http://jpcreativevision.co.uk/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^jpcreativevision\.co.uk
RewriteRule (.*) http://jpcreativevision.co.uk/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
ErrorDocument 404 http://jpcreativevision.co.uk/404.php

Forcing WWW And HTTPS (SSL) In .htaccess -- Requiring Assistance

I have found a thousand other topics asking for help with this, but none of their solutions seem to work for some reason.
I just purchased SSL for my domain a couple of days ago because I am accepting credit/check cards on my site and I want my customers to feel and be secure.
Anyways, this is what my .htaccess file looks like at the moment:
php_flag display_startup_errors off
php_flag display_errors off
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^buy-wow-accounts index.php [NC]
RewriteRule ^sell-wow-accounts sell.php [NC]
RewriteRule ^about-khaccounts about.php [NC]
RewriteRule ^buy-sell-wow-accounts-faq faq.php [NC]
RewriteRule ^khaccounts-feedback feedback.php [NC]
RewriteRule ^payment-plan payment-plan.php [NC]
RewriteRule ^customer-login customer-login.php [NC]
RewriteRule ^customer-center customer-center.php [NC]
RewriteRule ^privacy-policy privacy.php [NC]
RewriteRule ^buy-world-of-warcraft-wow-accounts/page-([0-9]+) listing.php?pageid=$1 [L,NC]
RewriteRule ^buy-world-of-warcraft-wow-accounts listing.php [L,NC]
RewriteRule ^world-of-warcraft-wow-acc/([^/]*)\.html$ account.php?acc=$1 [NC]
What I want to do is force WWW if it is not already in the URL and ensure that HTTPS (SSL) is forced as well. I have a ton of links out there to my site and most of them are just links like 'www.khaccounts.net', 'http://khaccounts.net', and 'khaccounts.net'.
I want to ensure that each of these different old links will be forced into having WWW and HTTPS. In order words, I want people to have the URL - 'https://www.khaccounts.net' no matter what URL they took to get to my site.
Thanks!
Right after your www rules add:
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Also, change your www rule to https:// so that there aren't 2 redirects.
Looks like you're rewriting all of your urls to the root. Why don't you try:
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}/$1 [R=301,L]
This works in showing the proper URL when khaccounts.net is hit, but still throws a redirect loop.
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.khaccounts.net/$1 [R=301,L,QSA]
Try replacing these lines :
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
With this :
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.khaccounts\.net$ [NC]
RewriteRule ^(.*)$ https://www.khaccounts.net/$1 [R=301,L,QSA]

I want to remove the www from url on https using .htaccess

I want to remove the www from https url by .htaccess.
for example
i want to change
https://www.example.com/ to https://example.com/
I have tried many rules
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.come/$1 [L]
and
RewriteCond %{SERVER_PORT} ^443
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule (.*) https://example.com$1 [L,R,QSA]
and
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
But nothing work. Please help me
Try:
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]
Please make sure if you are using X-Forwarding then try this one:
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

Rewrite rule for dynamic subdomain redirecting each file with subdomain arguments

I want to redirect all the calls to files in a subdomain with an extra variable. like if a user access www.domain.com/news.php and in the subdomain he accesses the same page then it should add an extra argument to the url like xyz.domain.com/news.php should be re written like it calls the file news.php?subdomain=xyz. Also i have other rules for just simple domain.
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,NC]
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$
RewriteRule ^$ /index.php?subdomain=%1 [L]
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,NC,L]
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ http://www.domain.com%{REQUEST_URI}?subdomain=%1 [L]
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^(.*)$ http://www.domain.com%{REQUEST_URI}?%{QUERY_STRING}&subdomain=%1 [L]
The solution pointed to by adaptr at: https://serverfault.com/a/409171/128746 - would solve this problem very well.

Resources