I need to redirect the main page only using htaccess as i've other redirects in the other folders.
I've tried
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [OR]
Rewritecond %{http_host} ^example.com [nc]
Rewriterule ^(.*)$ http://www.test.com/home/$1 [r=301,nc]
but it redirects the entire site and causes the rest of the redirects in the proceeding directories to not work.
Any help is truly appreciated.
Your rule ^(.*)$ means that any URL is redirected to http://www.test.com/home/$1 ; I think you just want to redirect /home/* and not the other directories, is it that ?
In that case, I think you simply need to change your rule to /home and not .*
Otherwise please give us some more information, 'cause it would mean I didn't understand your problem
RewriteEngine On
RewriteCond %{HTTP_HOST} ^expertshouse\.se?$ [NC]
RewriteRule ^(|/|/index.php)$ http://expertshouse.wix.com/home/ [R=301,L]
Related
I do want to add www to all requested domains. This works fine so far as long as I don’t use subfolders.
Example: http://domain.fr redirects to http://www.domain.fr but http://domain.fr/panel drops the slash, redirecting to a wrong url http://domain.frpanel
Here is my rule:
RewriteCond %{HTTP_HOST} !^www\.domain\.fr$ [NC]
RewriteRule ^(.*)$ https://www.domain.fr$1 [R=301,L]
Thanks for helping me
René
Try with below,
RewriteCond %{HTTP_HOST} !^www\.domain\.fr$ [NC]
RewriteRule ^(.*)/?$ https://www.domain.fr/$1 [R=301,L]
I am using the following condition/rule on a .htaccess file located at the root of my domain. The purpose is to redirect all non-www requests to their www. version:
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
It seems to be working fine.
Inside my /blog/ subdirectory I have another .htaccess that I use to redirect fancy URLs to real ones:
RewriteCond %{THE_REQUEST} !.*?url=.*
RewriteRule (.*) index.php?url=$1 [QSA]
This also seems to be working fine. However, all non-www requests inside the /blog/ subdirectory are not being redirected to their www. version.
For example, if I type domain.com on the browser I correctly get redirected to www.domain.com. But if I type domain.com/blog/ or domain.com/blog/test-page/ I won't get redirected to the www. version.
Probably the .htaccess inside /blog/ is conflicting with the one at root level, but I don't know how or how to fix it. Any clues?
Update: I solved the problem by putting all the rules on the root .htaccess file. I had to tweak the fancy URL rules slightly to only catch the /blog/... requests. Here's the final .htaccess file in case it might help you:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^apprush\.com$ [NC]
RewriteRule ^(.*)$ http://www.apprush.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/blog
RewriteCond %{REQUEST_URI} !.*?url=.*
RewriteRule blog/(.*) blog/index.php?url=$1 [QSA,L]
Are you able to put all of the rewrite rules into the root level .htaccess? It not only gets around the problem you're having but is a little neater because you know exactly where all of your rules are located.
If you are, these rules will do what you need:
RewriteCond ${HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
RewriteCond ${THE_REQUEST} !/blog/.*?url=.*
RewriteRule (.*) index.php?url=$1
This is because you have dollar sign $ at the end of domain.com. Also you need to use REQUEST_URI instead of HTTP_HOST. Remove it:
RewriteCond %{REQUEST_URI} ^domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
The dollar sign signifies the end of the string, thus making the rewrite to work for direct requests to domain.com. The update script solves the problem.
I would like to redirect a sub/sub folder url to a specific URL.
It works with normal redirections like:
Redirect /folder https://mydomain.com/therestoftheurl
But i need alot of folder/folder1 or folder/folder2 redirections.
It won't work with this:
Redirect /folder/folder1 https://domain.com/target
I found a reverse Question about this with this solution.
RewriteCond %{HTTP_HOST} ^mydomain.in$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.in$
RewriteCond %{REQUEST_URI} !^/users
rewriterule ^(.*)$ http://mydomain.com/$1 [R=301,L]
So if i'm not misstaken I could use this without "!" like so. But i think i'm missing something.
RewriteCond %{HTTP_HOST} ^mydomain.in$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.in$
RewriteCond %{REQUEST_URI} ^/folder/folder$
rewriterule ^(.*)$ http://mydomain.com/$1 [R=301,L]
and then the redirections which i don't know at this moment to write.
Thanks for the quick help.
You just need to re-order your directives so that the one with subfolders come before the parent redirect:
Redirect /folder/folder1 https://domain.com/target
Redirect /folder https://mydomain.com/therestoftheurl
This is my code, placed in my htaccess in the main directory of my domain. Trying to redirect country traffic (using mod_geoip) to my subdomain.
GeoIPEnable On
RewriteEngine On
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$ [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [R,L]
However, I'm getting a redirect loop error when I put it into practice. When I switch my Rewrite rule to go to domain.com and then put the file in sub.domain.com it seems to work. What is wrong with my code? Thanks!
Thanks Anubhava for your help. I looked around a bit and found this modification that seemed to do the trick. The change was made to the RewriteRule.
GeoIPEnable On
RewriteEngine On
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$ [NC]
RewriteRule !^(subdomain) http://www.subdomain.domain.com [L,R]
I put this in my .htaccess and it worked! I saw this use with redirecting with a subfolder as well.
Try this rule with an additional condition to avoid redirect when host is already sub.domain.com:
GeoIPEnable On
RewriteEngine On
RewriteCond %{HTTP_HOST} !^sub\.domain\.com$ [NC]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$ [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [R,L]
I'm not sure if this is possible, but here's whats going on.
I currently have an .htaccess rule to redirect example.com to store.example.com
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://store.example.com/[L,R=301]
This works great, however my search queries no longer work. What I'd like to do is redirect example.com to store.example.com unless I'm searching.
A sample search would look like this:
http://example.com/?s=my+search+query+string
Thank you in advanced for your help
Have you tried:
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{QUERY_STRING} ^!(s=(.*))$
Rewriterule ^(.*)$ http://store.example.com/ [L,R=301]