Wordpress .htaccess doesn't remove www from website's URL - wordpress

Looking at the code, this should be working (its working for other websites/subdomains i'm working on)
# 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]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/ [R]
</IfModule>
# END WordPress
Edit: the website is on a Redirect Loop now.

Fixed it going into Wordpress settings > General > Website URL and adding "www." to the domain :)

your redirect should be first before WordPress handles the request.
like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# 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

Related

subdomains for different wordpress directory

I have staging.namexx.my and staging2.namexx.my now.
for staging.made4u.my, it's using directoryA
And now, i want staging2.namexx.my to use directoryB to open wordpress
*staging.namexx.my is currently working, just need to let staging to use directoryA, and staging2 to use directoryB in same server.
I'm playing with the htaccess and google for some time but still cannot get it.
I need some help.
my htaccess in root
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(staging.)?namexx.my$
RewriteCond %{REQUEST_URI} !^/dicrectoryA/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dicrectoryA/$1
RewriteCond %{HTTP_HOST} ^(staging.)?namexx.my$
RewriteRule ^(/)?$ dicrectoryA/index.php [L]
</IfModule>
# END WordPress
htaccess in directoryA
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /dicrectoryA/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /dicrectoryA/index.php [L]
</IfModule>
# END WordPress
htacesss in directoryB
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /directoryB/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /directoryB/index.php [L]
</IfModule>
# END WordPress
Thank you!
To point staging2.namexx.my to directoryB via rewrite , you could use the following rule in your root/. htaccess .
RewriteEngine on
RewriteCond %{HTTP_HOST} ^staging2\.namexx\.my$ [NC]
RewriteRule ^ /directoryB%{REQUEST_URI} [L]
Just replace staging2.namexx.my with your real domain name and keep the rule block at the top of your htaccess.

Redirect a subdomain to a new URL

I have a client that had a main site in Joomla and a blog in WordPress. We just made everything one WordPress site.
What I need help with is redirecting the subdomain (e.g. blog.example.org) to the new URL (example.org/blog).
I believe this needs to get done with .htaccess and it needs to be integrated with the WordPress stuff, too.
Here's where I got so far:
# 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]
RewriteCond %{HTTP_HOST} ^example.health-access.org
RewriteRule ^(.*)$ http://example.org/blog/$1 [L,NC,QSA]
</IfModule>
# END WordPress
But it's not working. Any thoughts and help are greatly appreciated.
You just need to change the order:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.health-access.org [NC]
RewriteRule ^(.*)$ http://example.org/blog/$1 [R=301,L,QSA]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
#END WordPress
Try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yoursubdomain\.yourdomain\.com$ [
RewriteRule ^(.*) http://www.newdomain.com/?param=data&uparam2=data

https redirect in .htaccess doesn't work on homepage

I've recently activated SSL on a website (https://ledertid.com)
I use this in my .htaccess to redirect everything from http:// to https://.
This is my original .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
Then I tried this (Option A)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
The above option A returned the following error in the browser:
"ledertid.com redirected you too many times."
Then I tried this (Option B)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Option C
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
It works like a charm on all url's except for the homepage. So if you visit http:// ledertid.com it doesn't redirect you to the https:// version.
Is something wrong with my Rewrite rules in .htaccess or am I missing something else causing this problem?
Thanks a bunch in advance.
You can use this in your .htaccess:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
This will force HTTPs on every page including your homepage.
Please give this a try
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Also try putting the entire block before the wordpress stuff. Not inside it.

htaccess not redirecting and displaying 404

Im wondering if someone could help me out.
I have setup a 301 redirect from my .com.au to my com using htaccess which wordpress generated.
The homepage works fine except now everytime I try to navigate around my website I keep getting 404 errors
My htaccess is as follows
RewriteEngine On
RewriteCond %{HTTP_HOST} ^website\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.website\.com\.au$
RewriteRule ^/?$ "http\:\/\/www\.website\.com\/" [R=301,L]
# 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
Any help would be greatly appreciated
Thanks!
Try your rules this way. I also made a few changes to the first redirect rule.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?website\.com\.au$
RewriteRule ^/?$ http://www.website.com/ [R=301,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

.htaccess redirect directory to file

How do you redirect a directory (in this case /resume/) to a file (/Resume.pdf) using an .htaccess file? I have tried different rewrite methods but keep getting a redirect loop. Is this because of a conflict with WordPress?
This doesn't seem to work:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^resume/ http://domain.com/Resume.pdf [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Ok, I figured it out and here's what I got to work:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/resume$ [NC]
RewriteRule ^(.*)$ http://domain.com/Resume.pdf [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Resources