WordPress htaccess issue with www - wordpress

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

Related

htaccess redirects while moving to multisite under subdomain with tld change

I have a Wordpress website that is ranking well on www.domain.fr. I need to add english language. Fo this purpose I plan to convert the single site to WP multisite and I'd like to set www.domain.com for EN and move current FR language from www.domain.fr to fr.domain.com.
So my first aim is to redirect all trafic for all pages from https://www.domain.fr/* to https://fr.domain.com/*
Here is my htaccess
# 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
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain.fr$
RewriteRule ^(.*)$ https://fr.domain.com%{REQUEST_URI} [L,R=301]
While testing, it works fine for domain, says www.domain.fr is well redirect to fr.domain.com
But when I try www.domain.fr/any-page/ it does not work says server return www.domain.fr/a-page/ instead of fr.domain.com/a-page/
Any help would be appreciated
As #arkascha commented above I need to place the redirection before the internal rewriting rules.

Website Won't Load without WWW Prefix - 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.

htaccess redirect problems, Wordpress and static html site not redirecting properly

I'm having problems with a customer's website. I've created a new Wordpress site for him and now I'm having problems with htaccess redirecting.
Before I installed Wordpress on the server, there was two static basic HTML-sites. One in the public_html root using the main domain and a completely different subsite in a subfolder with a htaccess rewrite rule directing the subdomain into that folder.
Now there is Wordpress messing up the redirects. Wordpress of course made modifications to the original htaccess-file. In addition to that, the customer also had to change servers within the hosting provider to get newer php version so I had to write the htaccess file from scratch.
Here is the current htaccess-file :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /www/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /www/index.php [L]
</IfModule>
# END WordPress
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?subdomainurl.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subdomainfolder/
RewriteRule ^(.*)$ subdomainfolder/$1 [L]
Wordpress in installed in a folder named www and the url is being rewritten, it works beautifully. But I'm having problems with the subdomain. In the code above I've replaced the subdomain url with subdomainurl.com, the site lies in public_html/subdomainfolder/.
Now, when I type www.subdomainurl.com, the redirect works, the site is shown. But www.subdomainurl.index.html typed doesn't. It has to be written www.subdomainurl.com/subdomainfolder/index.html, so I'm clearly not writing the redirect right, adding the subdomain folder as well. I've tried to mingle with that htaccess but can't get it right. Everytime I try to change something I get a 404 in the main domain's Wordpress site.
At the moment these work:
www.maindomain.com/subdomainfolder/index.html
www.subdomainurl.com/subdomainfolder/index.html
And this doesn't, which I'm trying to do:
www.subdomainurl.com/index.html
I'm not a redirect expert, any help would be much appreciated.
Edit/Addon :
Here is the old code from the old server that redirected the subdomain to the subfolder and rewrote the url, it doesn't work anymore so I ditched it.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?subdomainurl.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subdomainfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdomainfolder/$1
RewriteCond %{HTTP_HOST} ^(www.)?subdomainurl.com$ [NC]
RewriteRule ^(/)?$ subdomainfolder/index.html [L]
I don't see an entry in the htaccess file for just the subdomain and for the main domain.
Currently I'm using this code
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /www/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /www/index.php [L]
</IfModule>
END WordPress
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?subdomainurl.com$ [NC]
RewriteCond %{REQUEST_URI} !subdomainfolder
RewriteRule ^(.*)$ subdomainfolder$1
This loads the whole secondary domain (subdomainurl.com) as www.subdomainurl.com/subdomainfolder and it works like that (www.subdomainurl.com/subdomainfolder/index.html, www.subdomainurl.com/subdomainfolder/work.html etc.), but it still isn't what the customer really wanted. I still need to eliminate the subdomainfolder-part from the url by htaccess, so far I haven't had success. I suppose I haven't got it right on the final row of the code.

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