Combining HTTPS redirection with rewrite rules cannot add .php extension
P粉098417223
P粉098417223 2024-04-04 15:44:30
0
1
389

Hope someone can help. I want to remove the file extension (.php) from internal links, but of course I need to configure it in htaccess first.

I believe the correct code is

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ .php [NC,L]

However, when I add this code below/above the pre-existing code (forcing https), nothing happens, i.e. I still need to put the .php Enter the URL.

After adding the above code, the htaccess file will look like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ .php [NC,L]
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(.*)$ https://mysite/ [R=301,L]

Any ideas why this doesn't work?

Thanks

I've been searching online but all posts say to just add the rewrite code to htaccess, unfortunately this doesn't work.

I don't think this code plays well with the existing code that forces https?

P粉098417223
P粉098417223

reply all(1)
P粉194919082

I think RewriteRule is too complex. I use the following for all my sites:

# append .php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .* rrreee.php [L]

# fallback to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!