Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

.htaccess redirect issue with multiple .htaccess file

I am using .htaccess file like below for redirect www to non www on my public_html directory

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

its working fine and redirect like below

    www.example.com
to
    https://example.com

Now in my sub directory called latest, I have another .htaccess file like below

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]

which is making my url clean like below

www.example.com/latest/index.php?page=1
to
www.example.com/latest/1

but even I have .htaccess file in home directory which is making www to non www, my this directory does not redirect www to non www.

I want redirect

www.example.com/latest/1
to 
https://example.com/latest/1

I am sure .htaccess file in my directory is causing issue but I do not know how to resolve it. Let me know if anyone here can help me for the same.

Thanks!

>Solution :

The problem is, mod_rewrite is not inherited (at least by default). If you have a rewrite rule in the "default" directory .. You’re going to have to include that rule in all subsequent directories "below" that. I have never seen (or heard of) a setting for allowing mod_rewrite to allow inheritance from parent .htaccess files. In general, this is just accepted as "the way it is".

UPDATE

THIS QUESTION In Server Fault explains this as well. The mod_rewrite rules from the previous htaccess files don’t even get processed.

COMBINE THE 2 in the SUB DIRECTORIES

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# add this only to sub directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading