I access a file on my root like example.com/demo/provider it is redirecting to www.example.com.
How can I correct this so that it will redirect correctly to www.example.com/demo/provider
What I have tried:
Try 1
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Try 2
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Try 3
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
I have tried some other codes too, Any suggestions will be appreciated Thanks!
Note: I already searched options available on Stackoverflow. But, none of answer worked for me. So, its not a duplicate question. I respect rules and terms of site.
My .htaccess file is in provider folder. You can take it as sub domain/directory.
If your htaccess is in the /provider folder then you have to use the full path to dir in target url,
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/demo/provider/$1 [R=301,L]
Or
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
This will correctly redirect your url from :
http://example.com/dir/foobar
to
http://www.example.com/dir/foobar
Related
i have the following rule to redirect non www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
but now i want a subdomain assets.company.com το be excluded but nothing seems to work for me
i have try
RewriteCond %{HTTP_HOST} !^assets\. [NC] [AND]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
and its not working
Pleas help
You can use this rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www|assets)\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Make sure to keep this as first rule.
Make sure to test this in a new browser to avoid caching issues.
All my website page URL's are redirected to have a www at the beginning. So, if someone types http//xyz.com it will automatically make it http//www.xyz.com. This is fine for me. But the main problem is, if someone types 123.234.111.121 it will again put a www at the beginning, which is wrong. How do I fix it? Any help in this regard is highly appreciated.
My current setup is as follows
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
I even tried with this...
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^50\.56\.246\.162
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
But, it still doesn't work
You can use this rule:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^[0-9]+\.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
This condition RewriteCond %{HTTP_HOST} !^[0-9]+\. will skip this rule if you supply an IP address to access the website.
The above rule as suggested by anubhava is not working for me also. I google around and came with this answer.
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I want to redirect non-www to www, and exclude a specific file (eg. testit.php). Cant find a working solution...
RewriteCond %{REQUEST_URI} !^testit.php
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
This redirects all files, including testit.php (which i want to exclude).
Thanks for help!
RewriteCond %{REQUEST_URI} !^/testit.php
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
I have referred all the related questions and tried the answer given, but it's not working for my site.
In my .htaccess file, I have written below code to redirect non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Are there any settings in Joomla that need to be set so it will use the .htaccess file?
This is what I use -
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
The differences are minor but should make it work. This works completely outside the scope of Joomla, you shouldn't have to do anything to Joomla for this to work.
You can put the following into your .htaccess to do this:
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
this works for me all the time
How can I redirect all non-www links to www links? I have found solutions on the internet, but they only redirect the domain name.
How do I make this general:
http://example.com/testing should redirect to http://www.example.com/testing?
try something like this
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.yourdomain.com/$1
If you want something generic that works for any domain, you can try something like:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(.+)$
RewriteRule ^(.*)$ http://www.%1/$1