For some odd reason when I visit my site without the "www." it redirects properly. However when I try to visit mywebsite.com/test.php it will redirect to mywebsite.com/public_html/test.php.
For some odd reason it adds "public_html" to the redirect breaking the page
My .htaccess is on the same level as the public_html place. Below is the code im using in the .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mywebsite\.com [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301,NC]
Related
I want my domain, theatrenearyou.org, to automatically redirect to www.theatrenearyou.org. I have a .htaccess file in my site's root directory along with some html files, but when I visit https://theatrenearyou.org it does not redirect to https://www.theatrenearyou.org
I'm using InMotionHosting, and I've made sure my .htaccess file is being read by testing out some redirects such as redirecting /pizza to /about.html. It seems like the .htaccess file is being read, but for some reason no matter what I do I cannot get it to force www.
This is what I currently have in my .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
This should redirect to https://www.theatrenearyou.org but instead the URL remains at https://theatrenearyou.org.
I have follwing htaccess for redirecting to www, https and index.html to /:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.html$ / [NC,R,L]
On the website I use a wordpress blog on /blog, which gives this error if I try to access it:
ERR_TOO_MANY_REDIRECTS
I can fix this by swaping the rule order, first comes redirect to www and then https, but then the redirect to www does not work
Okay I found the issue. As a programmer you really should check from time to time what people who have some access to site settings are doing.
In the wordpress login for the admin in settings -> general a custom domain was entered which was https://example.com/blog etc. which means wordpress blog redirected back to the version without www.
The fix is to add www to the wordpress setting.
I have the code below in my website's .htaccess file:
#redirect non www to http://wwww
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
This works fine but when I decide to access the forum on my site as a subdomain, the .htaccess is screwing everything.
So normally the url to forum is:
http://www.eetutorials.com/forum
but since I linked the forum folder as a subdomain, it does not work anymore and redirects to:
http://www.forum.eetutorials.com/forum/
which obviously is wrong! any idea how can I fix that by adding some conditions into .htaccess file?
You could change a condition:
RewriteCond %{HTTP_HOST} !^www\.
to this one:
RewriteCond %{HTTP_HOST} ^eetutorials.com$
I pretty much have this working. My problem is, as soon as I click on any link inside of the site, the subfolder name is added to the url. The modifications I have made to the htaccess file are all in the root directory, the one in the site directory is the standard joomla htaccess file. I am not sure if that is messing it up. Here is an example of the code.
To rephrase, I type the url into the browser "domain.com" The htaccess does its' job and changes that to "www.domain.com" automatically. I know that it is routing to the subfolder, because I can see the actual site. Then I click on the "Home" button as an example. The URL then shown in the address bar is "www.domain.com/site"
##### Redirect non-www to www -- BEGIN
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R,L]
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^/?(.*)$ http://www.domain.com/$1 [R=301,L]
##### Redirect non-www to www -- END
##### Subfolder redirect --BEGIN
RewriteRule ^(.*)$ /site/$1 [L]
RewriteRule ^(/)?$ site/index.php [L]
##### Subfolder redirect --END
I would be happy to post the entire htaccess file if needed, but I can tell you that through changing these two entries into it, I have gotten the site to where it is now. I have quite a few "security" measures in the file.
EDIT:
I should have put this in from the beginning, this is my attempt to redirect away from direct calls to the index.php. I just noticed that it may be fighting with my other redirect.
##### Redirect index.php to / -- BEGIN
RewriteCond %{THE_REQUEST} !^POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteCond %{SERVER_PORT}>s ^(443>(s)|[0-9]+>s)$
RewriteRule ^index\.php$ http%2://www.domain.com/ [R,L]
##### Redirect index.php to / -- END
EDIT 2:I have been constantly dumping my web cache from my browser for testing. My site seems to be running very slow right upon first connection and there is almost nothing on it as far as content. Have I added something that is requesting too much?
Can anyone suggest how I get non www traffic to redirect to the www version of a website using the htaccess file - I know I have one created in my root directory but cannot be sure what to put.. any ideas
Relatively easily.
Match anything that does not begin with 'www.' and then redirect to the 'www.' version:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]