2

My goals:

1. http://example.com/page/index.php -> https://example.com/page/
2. http://example.com/page/ -> https://example.com/page/
3. http://www.example.com/page/ -> https://example.com/page/
4. Any nonexistent file or directory requests -> index.php?&q=$1 for further processing.

Following rules work fine, but after a redirect in a browser URL instead of a clean URL

https://example.com/page/

i see

https://example.com/index.php?&q=page/

How to hide index.php?&q=page and show https://example.com/page/ in the URL? Before I added HTTPS redirect it worked fine for HTTP. I tried 2 solutions with the same result.

RewriteEngine on
RewriteBase /

#1 solution:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ [NC]
RewriteRule ^index\.php$ https://%{HTTP_HOST}/ [L,NE,R=301]

RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,NE,R=301]

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php?&q=$1 [QSA]


#2 solution:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ [NC]
RewriteRule ^index\.php$ https://%{HTTP_HOST}/ [L,NE,R=301]

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

RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php?&q=$1 [QSA]

0 Answers0