in my site i'm using a sesssion. In my htaccess i have got rules like:
RewriteRule ^([^-]+)/([^-]+)/$ index.php?page=$1&action=$2 [L,NC,NS]
RewriteRule ^([^-]+)/$ index.php?page=$1 [L,NC,NS]
It's work perfect. When someone create a session from www address, there is a problem with session on non-www address. It doesn't work.
When i'm add a rule to redirect from non-www to www:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
first rule like:
RewriteRule ^([^-]+)/([^-]+)/$ index.php?page=$1&action=$2 [L,NC,NS]
don't work and address looks like
index.php?page=link1&action=link2
What can I do in this case?
Thanks for help. Greetings
Related
in .htaccess Am using :
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1/$1/ [R=301,L]
It works fine for main domain i.e. redirects example.com to https://www.example.com
but not works on sub pages like
site.com/blog not redirects to https://www.example.com/blog
also like to add tailing slash '/' after url
https://www.example.com/blog/
how to achieve this?
Thanks in advance!
You should have htaccess rule like this. Make sure you keep these rules at the top of your htaccess file. Please clear your browser cache before testing your URLs.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI}/ [NE,R=301,L]
I have a website on a domain that I want to move to another domain. Here is my problem. The root URL has to redirect to a different location on the new domain. Example:
http://subdomain.olddomain.com/ must redirect to http://www.newdomain.com/location
http://subdomain.olddomain.com/code/slug must redirect to http://www.newdomain.com/slug
The htaccess code that I have doesn't work ver
RewriteRule ^/?(.*) http://www.newdomain.com/$1 [R=302,L]
This code works for the second example, but nog on the first. Can anyone help me setup the correct htaccess code?
Try:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.olddomain\.com$ [NC]
RewriteRule ^code/(.*)$ http://www.newdomain.com/$1 [L,R]
RewriteCond %{HTTP_HOST} ^subdomain\.olddomain\.com$ [NC]
RewriteRule ^$ http://www.newdomain.com/location [L,R]
I have a subdomain called es and I need when someone wants to enter mysite.com/es it can be redirect to es.mysite.com. It works with the following htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://es.mysite.com/$1 [R=301,L]
RedirectMatch permanent ^/es/?$ http://es.mysite.com/$1
The problem is when someone types mysite.com/es/bla/bla/bla. In this case, with the current configuration on my htaccess, the user isn't redirected and I want the user can be redirected.
For example:
If I enter:
http://letsbonus.com/es/barcelona/spa-experiencie-para-2-opcion-masaje-desconecta-roc-nature-273710
This is redirect to:
http://es.letsbonus.com/barcelona/spa-experiencie-para-2-opcion-masaje-desconecta-roc-nature-273710
Thanks in advance.
You need just this one rule in your root .htaccess of mysite.com:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?(mysite\.com)$ [NC]
RewriteRule ^es/(.*)$ http://es.%1/$1 [R=301,L,NE]
Your two rules enter into conflict:
Base url: http://example.com/es/test
Non-www redirection -> http://www.example.com/es/test
es subdomain redirection -> http://es.example.com/test
Non-www redirection... (we're no longer under www subdomain)
I would use this htaccess to get the excepted result:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www|es).example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteRule ^es/(.*)$ http://es.example.com/$1 [R=301,L]
I want to redirect an html page which is a contact form like this www.abc.com/contact.html to a different domain but without www like this xyz.com/contact.html.
I am having 2 domains with same data (Just the domain names are different). The form on xyz.com is working perfectly fine, but the form on abc.com is not working even though the code on both domains is 100% same.
Simply put the following lines in your .htaccess file.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www?.abc.com [NC]
RewriteRule ^contact\.html$ http://xyz.com%{REQUEST_URI} [R=301,L]
EDIT:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.abc.com [NC]
RewriteRule ^contact\.html$ http://xyz.com%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^abc.com [NC]
RewriteRule ^contact\.html$ http://xyz.com%{REQUEST_URI} [R=301,L]
I have been providing my subdomain name to friend until he manages to get new domain.
Now he has it and I would like to 301 redirect all the old links to his domain:
Example:
http://subdomain.my-domain.com/post.php?118&tg=602643
Redirect to
http://subdomain.com/post.php?118&tg=602643
So I want to keep up all the variables behind the post.php in the redirect
I am .htaccess newbie - can you please help me with providing the correct Rewrite rule?
Also, If you happen to have any good article about .htaccess and how to manage it, link is really appreciated.
Thanks
EDIT
Here are actual usecases I want to do:
redirect
http://raketa2.tasselhof.com/nastenka.php?115&up=648483
to
http://www.raketa2.cz/nastenka.php?115&up=648483
However, since there is no more subdomain existent on my site, i see the 404 error on my main page as this:
/nastenka.php?115&up=648483 -> Provided 404 Error
I tried:
RewriteCond %{Request_URI} ^/nastenka\.php [NC]
RewriteCond %{QUERY_STRING} ^\d+&tg=\d+$ [NC]
RewriteRule ^(.*)$ http://www.raketa2.cz/$1?%{QUERY_STRING} [R=301,L]
But with no good...
SOLVED
Duh! I am really dumb. I just added two new CNAME records to my domain DNS. Should do the trick
Do this:
RewrtiteEngine on
ReWriteBase /
RewriteCond %{HTTP_HOST} ^subdomain\.
RewriteRule ^(.*)$ http://subdomain.com/$1?%{QUERY_STRING} [R=301,L]
The QUERY_STRING post.php?118&tg=602643 will be present.
Assuming that there is no post.php on your domain,
Do this:
RewrtiteEngine on
ReWriteBase /
RewriteCond %{Request_URI} ^/post\.php [NC]
RewriteRule ^(.*)$ http://subdomain.com/$1?%{QUERY_STRING} [R=301,L]
If post.php is present on your domain but, you do not use similar query strings,
Do this:
RewrtiteEngine on
ReWriteBase /
RewriteCond %{Request_URI} ^/post\.php [NC]
RFewriteCond %{QUERY_STRING} ^\d+&tg=\d+$ [NC]
RewriteRule ^(.*)$ http://subdomain.com/$1?%{QUERY_STRING} [R=301,L]