Currently my Url is: http://www.domain.co.uk/index.php/city/details/city-name
I would like to change it to:
http://www.city-name.domain.co.uk/index.php/city/details/city-name
or:
http://www.city-name.domain.co.uk/city/details/city-name
Put the .htaccess file into the http ://www.domain.co.uk/ document root
To http ://www.city-name.domain.co.uk/index.php/city/details/city-name
RewriteRule ^(.*)/([^/]+)$ http://www.$2.domain.co.uk/$1/$2 [R=301,L]
To http ://www.city-name.domain.co.uk/index.php/city/details/city-name
RewriteRule ^index.php/(.*)/([^/]+)$ http://www.$2.domain.co.uk/$1/$2 [R=301,L]
If the server is the same, set above RewriteRule this line to prevent redirection loop
RewriteCond %{HTTP_HOST} !^www\.(.*).domain\.co\.uk [NC]
File content example
<ifModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.(.*).domain\.co\.uk [NC]
RewriteRule ^index.php/(.*)/([^/]+)$ http://www.$2.domain.co.uk/$1/$2 [R=301,L]
</IfModule>
To exclude domain.co.uk (whitout www)
<ifModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.(.*).domain\.co\.uk [NC]
RewriteCond %{HTTP_HOST} !^domain\.co\.uk [NC]
RewriteRule ^index.php/(.*)/([^/]+)$ http://www.$2.domain.co.uk/$1/$2 [R=301,L]
</IfModule>
Related
I'm trying to redirect all the connections to my website from http to https using htaccess and mod_rewrite, I've tried all the possible things and still not working, I get an error like: The page is not redirecting properly
Here goes the htaccess code:
ErrorDocument 404 http://www.example.com/error.php
<IfModule mod_rewrite.c>
Options -Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^([^/]*)\.html$ /index.php?lang=$1 [L]
RewriteRule ^sites/examplesite/([^/]*)\.html$ /index.php?lang=$1 [L]
RewriteRule ^([^/]*)/examplesite/([^/]*)\.html$ /index.php?lang=$1&page=$2 [L]
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?lang=$1&page=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ /index.php?lang=$1&idCat=$2&page=$3 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)\.html$ /index.php?lang=$1&cat=$2&filter=$3&pa=$4&page=$5 [L]
RewriteRule ^sites/examplesite/([^/]*)/([^/]*)\.html$ /index.php?lang=$1&page=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ /index.php?lang=$1&show=$2&page=$3 [L]
RewriteRule ^sites/examplesite/([^/]*)/([^/]*)/([^/]*)/([^/]*)\.html$ /index.php?lang=$1&itemID=$2&idCat=$3&page=$4 [L]
RewriteRule ^sites/examplesite/([^/]*)//([^/]*)/([^/]*)\.html$ /index.php?lang=$1&idCat=$2&page=$3 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)\.html$ /index.php?lang=$1&idCat=$2&client_id=$3&page=$4 [L]
</IfModule>
<FilesMatch "\.(ttf|otf|eot|woff)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
php_flag display_errors On
Regarding your main issue , from your code , this part i is what you think that will do forcing all http requests to https:
RewriteCond %{HTTPS} on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
and it is clear that you also want to add www for none www , so first , when you want to catch none https request , your should put like this line :
RewriteCond %{HTTPS} off
because it is condition like saying , if request not into https but in your code you only catch https requests themselves and force them again.
Put the following code instead of the above:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.yourwebsite.com/$1 [R=302,L]
Test it and if it's ok change 302 with 301 to get permanent redirection
I want to redirect example.com to example2.com, except for example.com/wp-admin
How do I redirect all pages on example.com to example2.com except for the subdirectory example.com/wp-admin?
I've tried:
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^wp-admin/$ [NC]
RewriteRule (.*)$ https://example2.com/$1 [R=301,L]
</IfModule>
but this does not work.
Help appreciated.
You can use this rule in site root .htaccess of example.com site:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule !^wp-admin/ http://example2.com%{REQUEST_URI} [NE,R=301,L,NC]
I'd like my htaccess file to make any url gone to with a www to be removed...
For example, if I was to go to:
https://www.mysite.com
I'd need to be redirected to:
https://mysite.com
The site is SSL encrypted, so all URL's should have https://
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^https://www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
</IfModule>
You can use this rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(example\.com)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301,NE]
Hi On our website we are facing a issue like when we enter url without www for eg. example.com/xyz in this case after redirect it is converting to www.example.com/?url=xyz but it should be redirect to simply like: www.example.com/xyz
So we are getting extra ?url= in URL
We have used code for redirect non www url to www in our htaccess file. Code for redirect in htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
We have also tried this code but not work:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
</IfModule>
Try placing your redirect rule before the routing rules:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
I have the following .htaccess code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mysite.co$ [NC]
RewriteRule ^(.*)$ http://www.mysite.co/$1 [R=301,QSA,L]
</IfModule>
The problem is that all subdomains get redirected to www.mysite.co/subdomain
How can I aviod this?
Your rewrite rule logic in plain speak is doing the following:
For ANY HOST other thant www.mysite.co (including foo.mysite.com, blog.mysite.com, etc..)
Permanent Redirect (301) to http://www.mysite.co/
This is the last rule to check in the .htaccess file, so bail out
To not redirect your own subdomains, the easiest and clearest way is to handle it explicitly with more rewrite conditions (see example below). For more kung fu htaccess fun try this: .htaccess Wildcard Subdomains
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mysite.co$ [NC]
RewriteCond %{HTTP_HOST} !^blog.mysite.co$ [NC]
RewriteCond %{HTTP_HOST} !^foo.mysite.co$ [NC]
RewriteRule ^(.*)$ http://www.mysite.co/$1 [R=301,QSA,L]
</IfModule>
You need to run your index.php file
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]+)\.example\.com$ [NC]
RewriteRule !^index\.php($|/) index.php/accounts/%2%{REQUEST_URI} [PT,L]