Website Won't Load without WWW Prefix - WordPress? - wordpress

We had this issue before with our old website, but only in certain browsers. We recently pushed our new website live and the issue now seems to be affecting all browsers. When you visit the website without the WWW prefix, you are taken to a "Under Construction" page that I'm told is a server error page of some sort.
Here is the domain:
www.mcfaddengavender.com
Here is my current .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Would it be possible to force all browsers to load the WWW prefix?

DNS propagation could explain why it does not work. No, you should not need to force browsers to reload with www (which I just saw you did). You should use a CNAME record in your DNS to map your www subdomain on your main domain.

Your .htaccess file looks fine and is normal.
You don't need anything in .htaccess to force or remove www with a Wordpress site. Add or delete the www prefix in Dashboard>>Settings>>General and save.

Not sure if this will solve the issue you're having, but to force a www in the domain name, you can add this above the # BEGIN WordPress line:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mcfaddengavender\.com$ [NC]
RewriteRule ^(.*)$ http://www.mcfaddengavender.com/$1 [L,R=301]

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mcfaddengavender\.com$ [NC]
RewriteRule ^(.*)$ http://www.mcfaddengavender.com/$1 [L,R=301]
This proccess is working for me.

Related

Wordpress: Force HTTPS using .htaccess

Problem
Using .htaccess to force HTTPs on my Wordpress site does not work
Tried solution
On my Wordpress site I have the following .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
But to force using HTTPs I'am trying to replace it with this code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} mydomain\.dk [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mydomain.dk/$1 [R,L]
</IfModule>
Result
The website is no longer working (here is the website response):
This page isn’t working
www.mydomain.dk redirected you too many times.
Try clearing your cookies.
ERR_TOO_MANY_REDIRECTS
Questions
Why can't I force using HTTPs on my Wordpress website?
What can I do to make it work?
Best regards, Henning
Before trying the surggested solutions - I tried to change the URL in the Wordpress settings to HTTPS and now it works.
Thanks for taking the time to answer my question, I was just about to try the Really Simple SSL plugin.
If your web server is running Apache, you can redirect all HTTP traffic to HTTPS by returning to the default .htaccess configuration and than adding the following code to your .htaccess file.
This is also the recommended method for redirecting WordPress to Apache:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
However, probably the easiest way to implement HTTPS on your WordPress site would be to install the following plugin:
https://wordpress.org/plugins/really-simple-ssl/

Rewrite HTTP to HTTPS works for main website but not WordpRess installation in /blog/

I am running a website with a WordPress installation contained within a /blog/ subdirectory. The Rewrite rules I have in place currently transform correctly for the main site, but not for the Wordpress install.
http://mywebsite.com
is transformed to
https://www.mywebsite.com
without issue.
However, these URLS:
http://mywebsite.com/blog/
http://mywebsite.com/blog/title-of-article/
are not transforming into what I want, which is this:
https://www.mywebsite.com/blog/
https://www.mywebsite.com/blog/title-of-article/
Is this a Wordpress issue, or is my .htaccess wrong?
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]
RewriteRule ^(blog/.*)$ https://www.mywebsite.com/blog/$1 [R=301,L]
UPDATE:
The new .htaccess, placed in the /blog/ directory, has made some progress.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mywebsite.com/blog/$1 [R,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
So mywebsite.com/blog/ is being transformed to https://mywebsite.com/blog/. Great! mywebsite.com/blog/article-title/ is being transformed to https://mywebsite.com/blog/article-title/. The issue is that the www. is not being added. They need to be https://www.mywebsite.com/blog/article-title.
Any ideas as to why the www. is missing?
UPDATE 2:
Turns out I forgot to add the "www." in the default URL in the Wordpress settings (General > Settings > Wordpress URL). With that set to https://www.example.com/blog/ and the above .htaccess in the /blog/ directory, all is now working.
It's better to manage rewrite rules separately by directories.
For blog folder, you should add the rewrite rule in .htaccess within blog folder.
If you want server-wide changes, you shouldn't use .htaccess and edit relevant details within the server configuration file.
/.htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]
/blog/.htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mywebsite.com/blog/$1 [R=301,L]
When adding .htaccess entries in WordPress directory, note that there is a section that will be automatically overwritten by WordPress.
As long as you place your own rules outside of # BEGIN WordPress and # END WordPress, the rules will stay.
Finally, you should also change your WordPress Address and Site Address within the WordPress settings (Settings > General) to use https instead.

WordPress htaccess issue with www

I have a WordPress website that is set to direct to www by default. Everything works perfectly, however I have a few sections that are custom coded, to go to "profile" pages of local services, accommodation etc. this works fine in development however on the live server when you access the link via www.example.com/services/example-here/ it redirects to example.com/wp-content/themes/theme-here/custom/services.php?slug=example-here
I've been told by my webhost that it is WordPRess that is causing the issue, however everything says www.example.com/ (siteurl etc.)
Here is the code in the htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^.*services/(.*)/$ /wp-content/themes/theme-here/custom/services.php?slug=$1 [QSA,L]
RewriteRule ^.*accommodation/(.*)/$ /wp-content/themes/theme-here/custom/accommodation.php?slug=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any ideas I've checked all my settings, Could it be a host issue inside of apache conf to do with mod re-write? I also might add that the code works perfectly without the www's added but my client requires the www.
Add a www forcing rule on top of this .htaccess just below RewriteBase / line:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
Make sure in your permalink settings of WP you have blog address with www

htaccess conflicting with wordpress htaccess

I have the following code in my htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I avoid editing the automated code by Wordpress because the changes may be erased and I'll have to do it all again. I have another site running the first three lines of code and it's working perfectly to replace example.com for www.example.com. That's all I really need for this example.com site but still preserving the Wordpress properties.
The problem
example.com is not redirecting to www.example.com but instead displaying a 301 error.
I'm using the following lines in all my WordPress-Sites before the # BEGIN WordPress. This should solve your problem. The L (for last) is the solution
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
"I avoid editing the automated code by Wordpress because the changes
may be erased and I'll have to do it all again."
You can avoid a WordPress installation from modifying its root .htaccess file.
Simply connect via FTP, or other means and chmod your WordPress root .htaccess file properties to 0444.
Where is the conflict? I can't see any conflict. WordPress only touches the lines after # BEGIN WordPress

Wordpress .htaccess www. not forcing

I'm trying to force www. on all the pages of my site.
I have wordpress install in a folder on my main site (/blog). In the /blog folder there is an .htaccess file with the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
In the main dir of the site. I have a .htaccess file that has the follow:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.sitename.com [NC]
RewriteRule (.*) http://www.sitename.com/$1 [R=301,L]
RewriteRule ^blog/index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.*)$ /blog/index.php [L]
In wordpress is have the option set for www. The www. appears on every page except the when I go straight the the site.com/blog address
Go Settings -> General:
WordPress Address (URL)
Site Address (URL)
And set both of them to www.yoursite.com (instead of yoursite.com), wordpress automagically takes care for setting all the urls to www.yoursite.com and that's it.
If that isn't enough, you shouldn't edit the .htaccess file anyway, because anytime you save or reload your permalink settings, Wordpress will overwrite your .htaccesss (some plugins may do that as well).
If you do want to rewrite your URL, you should do it with WP Rewrite (Codex), or if you want a little more simple approach, there is a good plugin for that called Redirection (Wordpress.org Plugin Directory).
In Redirection plugin you can just set the options to *.mydomain.com/* to redirect to www.mydomain.com/* with a 301, and that will take care of your htaccess as long as you keep the plugin active.
Hope this helps :)
RewriteCond %{HTTP_HOST} !^www\.(.*)
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
In the .htaccess of the WordPress installation (/blog/ in your case), you can add the following code ABOVE the line that reads # BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ "http\:\/\/www\.domain\.com\/subdirectory\/$1" [R=301,L]
</IfModule>
## Redirect primary WordPress URL to WWW version
Obviously, replace "domain.com" with your actual domain name and "subdirectory" with the name of the subdirectory where WordPress is installed. (/blog/ in the OP's request).
Have Option for you:
using wp-config.php add:
define('WP_HOME','http://www.domainname.com');
define('WP_SITEURL','http://www.domainname.com');
using wp-admin
Log into your wp-admin
Browse to ‘Settings’ -> ‘General’
Under ‘WordPress Address (URL)’ and ‘Site Address (URL)’ add www to the address as shown below

Resources