I want to redirect my domain landing page to other domain but I don't want to Redirect Everything After the Domain landing page.Can any one help me How I can do this. my htaccess file :-
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteCond %{HTTP_HOST} ^women\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.women\.com$
RewriteRule ^/?$ "http\:\/\/beta\.women\.com\/" [R=301,L]
I want women.com landing page redirect to beta.women.com but women.com?post_type=in_product&p=509&preview=1 or women.com/about or everything after women.com/ not to redirect to beta.women.com
any help will be highly appreciated !
Thank you !
Keep redirect rule before other rules and exclude any query string from redirect using a RewriteCond:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} ^(?:www\.)?(women\.com)$ [NC]
RewriteRule ^/?$ http://beta.%1/ [R=301,L]
RewriteRule ^index\.php$ - [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Related
I'm trying to redirect my subdmain in this manner: anysubdomain.my_domain.com and its URLs must be redirected to root domain and its URLs respectively.
For example (1) if a user tries http://anysubdomain.my_domain.com it should redirect tohttps://www.my_domain.com.
And (2) if a user tries http://anysubdomain.my_domain.com/anyurl it should be redirected to https://www.my_domain.com/anyurl.
I was able to achieve (1) using below htaccess code:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} !^www.my_domain.com$
RewriteRule ^(.*)$ https://www.my_domain.com/$1 [QSA,L,R=301]
</IfModule>
yet I could not do the (2) part. I'm sure we can do this with a modification for above htaccess code, but I don't know how.
I already have wildcard cname, that is why (1) perfectly working.
Also it is a WordPress site, if that matters.
Put these rules first :
RewriteCond %{HTTP_HOST} !^www.my_domain.com$
RewriteRule ^(.*)$ https://www.my_domain.com/$1 [QSA,L,R=301]
like this :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?my_domain\.com$
RewriteRule ^(.*)$ https://www.my_domain.com/$1 [QSA,L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Note: clear browser cache the test.
You may use this .htaccess to handle all subdomains:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} (?:^|\.)(my_domain\.com)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [NE,L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
Make sure to test it from new browser to clear browser cache fully.
I'm trying to redirect a single WordPress page (/scheduling/) to HTTPS, while forcing HTTP on all of the other pages. There are a lot of similar posts on this topic, but my specific use case isn't working for some reason. Thoughts?
.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} ^scheduling/
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^scheduling/
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The above is properly redirecting all other pages to be redirected to http whenever https is requested, but isn't doing anything at all for the scheduling/ page.
Do redirects before default WP rule.
Use THE_REQUEST variable instead of REQUEST_URI.
You can use:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} /scheduling [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} !/scheduling [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I tried doing some .htaccess redirects for internal pages but they are not working for me. This is my .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteRule articles articles/how-to-play-piano [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
I also tried this outside <IfModule> but not working:
Redirect 301 http://www.domain.com/articles http://www.domain.com/articles/how-to-play-piano
and
Redirect 301 /articles http://www.domain.com/articles/how-to-play-piano
Your regex is wrong for articles rule and will cause infinite looping. To fix that you need to use anchors ^ and $:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteRule ^articles/?$ articles/how-to-play-piano [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
How would I exclude a subdomain from getting forced to https and redirected to main url? I'm using the below in my .htaccess file but need a little help as my subdomain (stage.mydomain.com) gets redirected / can't access.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I've tried a few options but no luck - Any ideas? Thanks!
Have your first rule like this:
RewriteCond %{HTTP_HOST} !^stage\.mydomain\.com$ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
I'm trying to redirect all urls that contain a specific string. The urls look like this
http://www.domain/com/modules.php?name=Kalender&op=list&d=8&m=6&y=2034
I have to redirect all urls that contain
name=Kalender&
to
http://www.domain.com/kalender/
I tried several rules in my .htaccess. None of them worked:
RewriteCond %{REQUEST_URI} name=Kalender&
RewriteRule .* kalender
RewriteRule ^(.)name=Kalender&(.)$ http://www.domain.com/kalender/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/name=Kalender&/i$ http://www.domain.com/kalender/ [NE,L]
RewriteCond %{REQUEST_URI} name=Kalender&
RewriteRule ^(.+)$ http://www.domain.com/kalender/ [L,R=301]
RewriteCond %{QUERY_STRING} ^name=Kalender&
RewriteRule ^name=Kalender& http://www.domain.com/kalender/ [R=301,L]
RewriteRule ^(.*)name=Kalender&(.*)$ http://www.domain.com/kalender/ [L,R=301]
RewriteCond %{REQUEST_URI} ^/modules.php?name=Kalender&$
RewriteRule ^(.*) http://www.domain.com/kalender [R=301,L]
This is the WordPress .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Any help would be appreciated!
You can use this rule as your first rule:
RewriteCond %{QUERY_STRING} (^|&)name=Kalender(&|$) [NC]
RewriteRule ^ /kalender/? [L,R]