英文:
Modify .htaccess for redirect php to html except for one page to be ignored
问题
I use a custom php script (php v.7) and have 5 php pages:
index.php, product1.php, product2.php, product3.php, admin.php.
This htaccess code redirects non-www to www, http to https and php pages redirect to .html format.
Question: how can I redirect from php to html only on 4 of the 5 pages, to add an ignore rule for admin.php? I don't want to have php to html redirection for the admin.php page.
Thank you in advance!
I tried more than 15 variants and none of them worked in 4 hours of searching on stackoverflow.
英文:
I use a custom php script (php v.7) and have 5 php pages:
index.php, product1.php, product2.php, product3.php, admin.php.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+?)\.php$ /$1.html [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)\.html$ /$1.php [L]
</IfModule>
<FilesMatch ".(ico|css|jpeg|png|woff|woff2|webp)$">
Header set Cache-Control "max-age=604800, public, no-cache"
</FilesMatch>
Options -Indexes
This htaccess code redirects non-www to www, http to https and php pages redirect to .html format.
Question: how can I redirect from php to html only on 4 of the 5 pages, to add an ignore rule for admin.php?
I don't want to have php to html redirection for the admin.php page
Thank you in advance!
I tried more than 15 variants and none of them worked in 4 hours of searching on stackoverflow
答案1
得分: 0
You can add RewriteCond %{REQUEST_URI} !^/admin.php$
before RewriteRule
to ignore the admin.php
page.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} !^/admin.php$
RewriteRule ^(.+?)\.php$ /$1.html [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)\.html$ /$1.php [L]
英文:
You can add RewriteCond %{REQUEST_URI} !^/admin.php$
before RewriteRule
to ignore admin.php
page
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} !^/admin.php$
RewriteRule ^(.+?)\.php$ /$1.html [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)\.html$ /$1.php [L]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论