.htaccess domain language redirect to folders - .htaccess

I have this situation:
When somebody goes to www.example.com, it should display www.example.com/en/
When somebody goes to www.example.fr, it should display www.example.com/fr/
Can you help me with htaccess setup?
Thank you guys!

Simple solution for .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} www.example.fr$ [NC]
RewriteRule ^$ http://www.example.com/fr/ [L,R=301]
RewriteCond %{HTTP_HOST} www.example.com$ [NC]
RewriteRule ^$ http://www.example.com/en/ [L,R=301]

Related

Redirect with htaccess if url of multiple subdomain not contains directory

And I have a lot of subdomain:
sub1.abc.com, sub2.abc.com,.., subn.abc.com with the same directory: true-dir-1, true-dir-2, true-dir-3
I want to
If url not contains (true-dir-1, true-dir-2, true-dir-3) then redirect to subdomain
For example:
sub1.abc.com/false-dir redirect to sub1.abc.com
sub2.abc.com/false-dir redirect to sub2.abc.com
Pls help me use .htaccess to redirect it..
Thanks so much!
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub1\.abc\.com$ [NC]
RewriteRule !^true-dir-1 / [L,NC,R=302]
RewriteCond %{HTTP_HOST} ^sub2\.abc\.com$ [NC]
RewriteRule !^true-dir-2 / [L,NC,R=302]
RewriteCond %{HTTP_HOST} ^sub3\.abc\.com$ [NC]
RewriteRule !^true-dir-3 / [L,NC,R=302]
You can use that:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.abc\.com$ [NC]
RewriteRule !^%1 / [L,NC,R=302]
Change [R=302] for [R=301] when test work well.

how to remove www from all urls of my website domain using htaccess

I want to remove www from all urls of my website domain. I used following code
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
But this code redirects only http://www.example.com to http://example.com
i want http://www.example.com/abcd as http://example.com/abcd also
Please help me. your help would be appreciated. Thanks in advance.
You can use this rule in root .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(example\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L,NE]
Make sure to test this in a new browser.
try this
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "http\:\/\/example\.com\/" [R=301,L]

htaccess rewrite condition a folder

I'd like to redirect demo.mydomain.net/p/ to mydomain.net/.
I saved the .htaccess on my demo.mydomain.net/p/ folder but it gives me the 500 Internal Server Error.
Here's my .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^demo\.mydomain\.net\p$ [OR]
RewriteCond %{HTTP_HOST} ^www\.demo\.mydomain\.net\p$
RewriteRule ^/?$ "http\:\/\/mydomain\.net" [R=301,L]
Can anybody help me out?
Thanks in advance!
Can you test your rules:
RewriteEngine on
RewriteCond %{HTTP_HOST} demo\.mydomain\.net$ [NC]
RewriteRule ^$ http://mydomain.net/ [R=301,L]

RewriteRule at htaccess wrong redirect

ive this rules at htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^site.com [NC]
RewriteRule ^(.*)$ http://www.site.com/$1 [L,R=301]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^warcraft$ www.site.com/forumdisplay.php?f=480 [R=301,NE,NC,L]
issue happend when redirect warcraft its redirect to
http://www.site.com/home/site/public_html/www.site.com/forumdisplay.php?f=480
any tip ?
I suppose you want to redirect it to http://www.site.com/forumdisplay.php?f=480
If so put it in your .htaccess file:
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^warcraft$ http://www.site.com/forumdisplay.php?f=480 [R=301,NE,NC,L]
You must provide the full URL including protocol in your rule, in this case http://www.site.com/.....

redirect one domain to another with htaccess rules

I was wondering how i can redirect my users from my old domain to a new url
forexample
http://www.5.joblessbuddy.com/news.html
into this
http://www.1.joblessbuddy.hu/news.html
i did this on my htaccess but not working
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} http://www.5.joblessbuddy.com/$ [NC]
RewriteRule ^(.*)$ http://www.1.joblessbuddy.hu$1 [R=301,L]
any suggestion would be appreciated
thanks in advance
Try this:
RewriteCond %{HTTP_HOST} (www\.)?5\.joblessbuddy\.com [NC]
RewriteRule ^(.*)$ http://www.1.joblessbuddy.hu/$1 [R=301,L]
btw: mod_rewrite cheat sheet v2 is your friend.

Resources