I'm having a strange problem with an ExpressionEngine 1.6 site. I have added a page, and some people have had difficulty accessing the page with www. in front of the URL. Without the www, there seem to be no problems. It also seems to depend on which browser I am using - if I use Chrome, I cannot see the page with www in the URL, but I can if there is no www. Other browsers work whatever. I've tried clearing cache in Chrome to no avail.
What on earth could the problem be?
Here's the code in .htaccess, in case it's something to do with that.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]
RewriteCond %{QUERY_STRING} ^utm_medium
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteRule (.*) /index.php?/pages/index/&%{QUERY_STRING} [L]
</IfModule>
It's not ideal to have a site that's accessible on both the www and no www as this will mean your Google listing gets diluted due to duplicate content. By eliminating the www you will also resolve your issue:
# Remove the www from the URL
# ------------------------------
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Should go after the line "RewriteBase /" and before your main rewriting.
The alternative is to add the www:
# Add the www to the URL (use instead of www removal)
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^localhost [NC]
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
That said, to try and specifically solve the issue, I'm assuming that other pages are fine and it's just this page in particular? Also can the page be accessed by including the index.php/ in the path?
This rewrite seems a bit strange:
RewriteCond %{QUERY_STRING} ^utm_medium
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteRule (.*) /index.php?/pages/index/&%{QUERY_STRING} [L]
If this line is the culprit and relevant to the page causing issue, try changing the last line:
RewriteRule ^(.*)$ /index.php?/pages/index/&%{QUERY_STRING} [L]
or
RewriteRule (.*?)index.php?/pages/index/&%{QUERY_STRING} [L]
Related
For re-directing all requests without “www.” or with “http:” I was using the following .htaccess settings since activating SSL:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{SERVER_PORT} !^443
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^index\.php/(.+)$ /$1 [R=301,L]
RewriteRule ^index\.php/?$ / [R=301,L]
I now noticed that my former redirections of index.php to / don’t work anymore, if the requested URL is http.
Also, I now need to change current .html files (half of my website) to .php and add this:
RewriteRule ^(.*)\.html$ $1.php [L]
I would like to use as little rewrites as possible to maximize SEO effects, but I got stuck trying around. Any help would be greatly appreciated.
After trying around for some more hours, I think I came to an elegant solution:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)index\.php/?$ [OR]
RewriteCond %{REQUEST_URI} ^(.*)index\.html/?$
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/ [R=301,L]
# index.php or index.html are sent to https://www.domain.tld/
RewriteCond %{REQUEST_URI} ^(.*)\.html$
RewriteRule ^(.*)\.html$ https://www.%{HTTP_HOST}/$1.php [R=301,L]
# .html is changed to .php and additionally redirected to https://www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{SERVER_PORT} !^443
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Everthing not redirected before, gets an additional www. and/or is redirected to https.
I'm happy about comments and recommendations to improve further, if neccessary. Hope this is helpful to anyone.
I've installed Drupal 7 to a sub-directory on my server and used .htaccess mod_rewrites to fix most of the URL pathing issues, I'm now looking for a way to strip the sub-directory from the URL when it's explicitly requested.
To be clear, the site can be accessed from 'example.com' and the internal links work fine, but I'm looking to prevent requests to 'example.com/sub/file' from working, Ideally with a 301 back to 'example.com/file'.
My .htaccess at the moment looks like this:
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^$ sub/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/sub%{REQUEST_URI} -f
RewriteRule .* sub/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* sub/index.php?Q$0 [QSA]
Have you tried adding:
Redirect 301 /\/sub/file http://www.example.com/file
to your .htaccess?
I am using following htaccess file to achieve some redirections etc:
RewriteEngine On
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTPS} !=on
RewriteRule .* https://www.myurl.com/$1 [R,L]
RewriteRule ^$ /home [R=301,L]
Lately i ve added the latest line so when user visits https://www.myurl.com he gets redirected to https://www.myurl.com/home for the homepage. This works fine as wanted but i have a bad feeling that this should be written somehow better. I don't like the ^$ part but it works. How could i rewrite this?
The HTTPS part can definitely be rewritten and should come first as you're creating multiple redirects.
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
#redirect all traffic looking for a domain not starting with www &
#all non-https traffic to the https://www domain
RewriteCond %{HTTPS} off
#This condition is better for analytics tracking and SEO (single subdns)
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteRule ^$ home [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Since your MVC is likely using index.php to process all requests it's likely that the redirect to /home will not work unless you're visiting the website without requesting any file (the root only). If someone explicitly requests https://www.myurl.com/index.php your rule that says RewriteRule ^index\.php$ - [L] tells the site to not change anything. Since you said this is working as expected I've not changed the order.
If it doesn't work as intended, then switch the order of the rule for /home.
RewriteRule ^$ home [R=301,L]
RewriteRule ^index\.php$ - [L]
Here is my .htaccess file
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^. /archive/index.php [L]
going to domain.com will redirect me to www.domain.com
however, going to domain.com/2011/11/18/blog-title will show http://domain.com/var/htdocs/public_html/ instead in the browser URL.
My objective is any page at domain.com will redirect to www.domain.com
and wether I go to www.domain.com or domain.com /YYYY or /YYYY/MM or /YYYY/MM/DD will pass a PHP REQUEST_URI so I can get data from a MySQL database.
I originally copied the .htaccess file from WordPress but it doesn't seem to work properly since /var/htdocs/public_html appears in the browser URL bar.
This will do the trick:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Or this if you want a specific domain:
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
The rules are from Drupal 7 and Drupal 6 respectively and have always worked well for me
EDIT
Looking at your code again I think the only problem is that you don't have a / between http://www.domain.com and $1. Other than that it's pretty much identical to the second example above which definitely works
Firstly, I would like to remove the www. from my domain name
http://www.example.com => http://example.com
I would also like for certain directories to be secure (https), while the rest remain http
http://example.com/login => https://example.com/login
Obviously it needs to work for all conditions, for example if someone types in:
http://www.example.com/login => https://example.com/login
Also when people navigate away from the login page it returns to http. Currently in the .htaccess is the following which is done automatically by the software I am using and I suppose needs to be there for it to work:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php
Any ideas on how I can achieve dream control all these things?
Thanks in advance!
===================
#Gumbo Following your advice this is my complete .htaccess
RewriteEngine On
# remove www from host
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]
# force HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(login)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# force HTTP
RewriteCond %{HTTPS} =on
RewriteRule !^(login)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php
Options -Indexes
Navigating to http://example/login still goes to http://example/index.php when it should go to https://example/login Do I have the order wrong?
Try these rules:
# remove www from host
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]
# force HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(login|foo|bar|…)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# force HTTP
RewriteCond %{HTTPS} =on
RewriteRule !^(login|foo|bar|…)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
You also might want to add some additional conditions to only change the protocol on GET and HEAD requests but not on POST requests.
This code works for me:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
remove www (tested):
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^www\.yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://yoursite.com/$1 [L,R=301]
redirect (not tested):
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{THE_REQUEST} \/login/?.*\ HTTP [NC]
RewriteRule ^(.*)$ https://yoursite.com/login [L,R=301]
After reading this all post time line i have get success for following error: My website(c4dprime.com) was attached https: in mozilla firefox browser. Google and internet explore are show domain address as http: (The real problem in firefox) I did not want https: for my domain in any browser because one unknow redirect attached with my domain by https: (Cause for this error)after Installing following plugins in wordpress,(Easy redirect for ssl).... I have told to every one do not use any low level plugins for wordpress.
Anyway! After reading many articles and tutorials at this topic via google search engine. Now i am happy to say i have solve this problem from this post tips. Remember one thing about me i am new to in this form and wordpress.
This tip is help full for me
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^www\.yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://yoursite.com/$1 [L,R=301]
After edit or some changes in my .htaccess file following code i have use now with solved this error.
AddHandler c4d-prime .com
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteBase /
RewriteRule ^$ http://www.c4dprime.com/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress