I have domian test.com but redirection domian is test2.com/folder (and this is show in url) how get only show test.com?
your still showing i try
RewriteCond %{HTTP_HOST} ^test\.com$ [NC]
RewriteRule (.*) https://test2.com/folder$1 [P]
but show test2.com/folder
Related
WHAT I HAVE
Thanks to this discussion I've solved the problem of the "always https" redirect using this in my .htaccess:
# Redirect to httpS by default
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect to www if third level domain is not set
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
WHAT I WANT
As per the current configuration, https://example.com is correctly redirected to https://www.example.com.
BUT I need that if the URL contains wp-admin it isn't redirected to www.
So, for example, https://example.com/wp-admin hasn't to be redirected.
And also every subpage of the path wp-admin hasn't to be redirected.
https://example.com/wp-admin/login.php has to be visible without redirecting to www but from the second level domain.
CONTEXT (if you are curious about why I need this configuration)
I have the domain example.com.
This domain has some third level domains and has a Wordpress admin area at example.com (second level):
example.com
www.example.com
help.example.com
another.example.com
But
www.example.com is a Symfony app that runs on Heroku;
example.com is a Wordpress multisite installation that runs on DigitalOcean;
help.example.com and another.example.com are Wordpress sites handled with the multisite of example.com
For these reasons I need to redirect the second level domain to www if in the path there isn't wp-admin. In all other cases I need the redirect to www.
You want redirect "http to https" ?
put this in htaccess
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Ok, it was as simple as adding a second RewriteCond.
The complete .htaccess is this:
# Aerendir - Force SSL
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Then redirect to www
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteCond %{REQUEST_URI} !wp-admin [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
Note: Before you mark it duplicate, please read the complete question.
I already applied bellow suggestion which didn't work for me.
1 - mod rewrite from .domain to www.domain htaccess
2 - .htaccess redirect from http://www.domain/ to https://domain.com
3 - .htaccess redirect any domain/directory to www.domain/directory
We've got a shopping site which we're hosting on a host (CloudLogin).
The main site is built on Joomla CMS and Magento as shopping cart.
The main site URL is www.domain.com and shopping cart URL is domain.com/shop (Without www).
What we need is to show both URLs with (www).
So we need the Magento folder ie domain.com/shop also to be on www URL.
I found some solutions on stack overflow but they didn't work for me as it always show a message browser (Too many redirection or /page isn't redirecting properly)
Note: The .htaccess file is located in (shop) folder.
Bellow is what I tried so far:
1 -
# anything.com to www.anything.com
RewriteCond %{HTTP_HOST} ^[^.]+(\.[^.]+)?$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301,NE]
The above code removes the (shop) directory from URL which turns into error.
ex: domain.com/shop/cat1/prod1 turns into www.domain.com/cat1/prod1
2 -
RewriteCond %{REQUEST_URI} !^/shop/?.*$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
Above code not even apply www on it.
3 -
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Above code redirects from domain.com/shop/cat1/prod1 to www.domain.com/shop with error message (redirected you too many times.)
Which seems infinite loop on page.
4 -
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*) http://www.domain.com/shop/$1 [L,R=301]
This does the same thing as 3.
5 -
#RewriteCond ${HTTP_HOST} doamin.com [OR]
#RewriteCond ${HTTP_HOST} www.doamin.com
#RewriteRule ^(.*)$ http://www.doamin.com/shop/$1 [QSA,R=301,L]
Does anyone know how I can always force the correct use of .htaccess for particular URLs?
I've had a look around SO but couldn't find a suitable answer to this.
Try :
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/shop
RewriteCond www.%{HTTP_HOST} ^(?:www\.)?(www\..+)$ [NC]
RewriteRule ^ http://%1/shop%{REQUEST_URI} [NE,L,R]
Did you try the following?
# anything.com to www.anything.com
RewriteCond %{HTTP_HOST} ^[^.]+(\.[^.]+)?$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/shop/$1 [L,R=301,NE]
Since requests originate from the /shop directory they will not contain that directory in the URL requested.
One of my site is redirected to another site like this :
http://cccc-xyz.ch is redirected to http://abc.ch
Now want if the redirection is coming from http://cccc-xyz.ch, it should redirect to http://abc.ch/cccc-xyz-page by writing htaccess in http://abc.ch.
I believe this should work
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://cccc-xyz.ch [NC]
RewriteRule ^ http://abc.ch/cccc-xyz-page/ [L,R]
I have the domain www.oldsite.com and i set a redirect to forward to www.newsite.com/new
but when i google search old site all of its sub links go to www.newsite.com/new/sublink
How do i edit the htaccess file so that the sub links never pass though
RewriteCond %{HTTP_HOST} ^oldsite\.com*$ [OR]
RewriteCond %{HTTP_HOST} ^www\.oldsite\.com*$
RewriteRule ^/?$ "http\:\/\/www\.newsite\.com\/new" [R=301,L]
In short all links involved in oldsite.com should redirect to newsite.com/new
I read the below but it didnt seem to help to much.
htaccess: domain hosted on subdirectory
The below .htaccess should be place on the root folder of the old domain only:
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC]
RewriteRule ^ http://www.newsite.com/new [R=301,L]
It will redirect anything from the old domain to the new one, for example:
http://oldsite.com/someurl
Will go to:
http://www.newsite.com/new
No URLs from the old site will be passed down to the new site, they will all be sent to /new.
NOTE: make sure you do not have any additional .htaccess files in other folders of the old domain as those will set null the previous rules.
If you want to send only the main domain to the new one without any URLs within:
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC]
RewriteRule ^/?$ http://www.newsite.com/new [R=301,L]
A different way would be to handle all the URLs on the new site, which would be like the below .htaccess:
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC]
RewriteRule ^ http://www.newsite.com/new%{REQUEST_URI} [R=301,L]
It will redirect anything from the old domain to the new one, for example:
http://oldsite.com/someurl
Will go to:
http://www.newsite.com/new/someurl
If you do not wish the new to show up simple remove /new from the rule above.
I'm having a problem with our site, in homepage it is working appropriately but when I visit the inside pages it returns 302 Found and keeps on redirecting, I used the logs in inspector element. In chrome it is working, but in ie11 and firefox it keeps on redirecting.
Here is my htaccess:
RewriteEngine On
#
# Full path to your site
#
# RewriteBase /
#
# Rules
#
#RewriteCond %{HTTPS} off
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#RewriteCond %{HTTPS} on
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
#RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?do=$1
ErrorDocument 404 /error
you can check this link to see what im talking about. http://mst.com.ph and then try: http://mst.com.ph/category/motoring/
After inspecting your page, /motoring/category is send with a 302 Moved Temporarily header. The location is however empty. I am assuming that the php page you are trying to load has a header( ... ) in it, and that the variable that contains the new location is empty or NULL. Besides that, the request is not terminated with an exit(), so the content is shown anyway. Chrome decides to ignore the status code and display whatever you sent as content after it, and other browsers apparently decide to redirect to the same page. In any case, it doesn't make sense to serve the page with a 302 status code.
This is not a problem with your .htaccess. In your script, make sure that variables contain what you believe they should contain. (var_dump(..) them for example). Also add an exit() behind headers that define a redirect.