Two RewriteEngine On rules? - .htaccess

Is it fine to have two RewriteEngine On rules in the .htaccess file, like here? Wordpress added automatically the new module.
Also, is it necessary to have the double RewriteBase / rules? Files are in the root directory.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,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

it would not harm, second call would be ignored, but you might as well edit file and clean up:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Related

redirect http to https making a problem in subdirectory as 404 - Not found

htaccess in root folder
#<IfModule mod_rewrite.c>
#RewriteEngine On
#Uncomment these two lines If you want to redirect http to https
#RewriteCond %{HTTPS} off
#RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ index.php [L]
#</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^https://3pmix.com/ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
htaccess in sub folder
RewriteRule ^classes/.*$ - [F,L]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_URI} config.php|db.php|functions.php [NC]
RewriteRule .* - [F,L]
directory structure through images
With your shown samples, please try following Rules file. Also make sure to clear your browser cache before testing your URLs.
Have your root htaccess Rule file like as follows:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^3pmix\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
</IfModule>
And have your sub directory htaccess Rules file as follows:
RewriteOptions InheritBefore
RewriteEngine ON
RewriteRule ^classes - [NC,F,L]
RewriteRule (?:config\.php|db\.php|functions\.php) - [NC,F,L]
I have also fixed flags and regex in your htaccess files.
Rewrite base was missing that is why was not finding the root url of the website
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>

https://gatorinsurances.com working but https://www.gatorinsurances.com not working

I've just install SSL for the first time. I've gotten a problem, https://gatorinsurances.com will resolve but https://www.gatorinsurances.com will not resolve.
My .htaccess code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Force https and remove www
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://gatorinsurances.com%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
</IfModule>

htaccess redirect 301 https www to non www

Currently only the homepage is redirecting from www.example.com and example.com to https://example.com
I try to redirect:
1. http://www.example.com/otherpages to https://example.com/otherpages
2. http://example.com/otherpages to https://example.com/otherpages
3. https://www.example.com to https://example.com
3. https://www.example.com/otherpages to https://example.com/otherpages
Tried to use some former questions but can't figure it out.
current state in .htaccess is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://my-domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.my\-domain\.com [NC]
RewriteRule ^(.*)$ http://my-domain/$1 [L,R=301]
</IfModule>
Thanks in advance
You don't need all that code for the conditions you want. Replace your all of that code with this and change to your domain.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !^on [OR]
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

.htaccess redirect example.com/magento/index.php to example.com/?

I have Magento installed in a subdirectory, the path to Magento is example.com/magento.
I have an .htaccess file in the root, 'example.com' as follows:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{http_host} ^example.com [NC]
RewriteRule ^magento/(.+)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/magento(/.*)?$ [NC]
RewriteRule ^(.*)$ /magento/$1 [QSA,L]
In the standard Magento .htaccess in example.com/magento I have uncommented the RewriteBase directive as follows:
RewriteBase /magento/
But when I type example.com the browser shows example.com/magento
How could I solve this issue?
Leave RewriteBase commented
# RewriteBase /magento/
Try this, instead, in your /.htacccess:
RewriteEngine on
RewriteRule ^(.*)$ /magento/$1 [L]
RewriteRule ^(.*)$ /index.php/$1 [L]
and add this to your magento/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . / [L]
</IfModule>

htaccess: How to redirect non-www url to my www-url

Currently my site can only be visited when visiting www.mysite.net or http://www.mysite.net. How can I change this so that when one just visits http://mysite.net, that you will be directed to www.mysite.net?
Here is my current HTACCESS file content
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I also tried this...
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %mysite.net !^www\.
RewriteRule (.*)$ http://www.%mysite.net/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Thank You
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
edit:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
edit 2
Add URL Rewrite Rule To Wordpress this is not helpful?
You Must Use This Code In htaccess File To Preferred www Version:
RewriteCond %{HTTP_HOST} !^(.).YourDomain.com$ [NC] RewriteRule ^(.)$ http://www.YourDomain.com/$1 [R=301,L]

Resources