[英]How do I URL Rewrite for below situation?
我在以下網址處有一個網頁。
https://example.com/contact.php
現在我要配置URL重定向之類的。 如果用戶打開的頁面具有完整的URL,則應自動從URL中刪除.php。
https://example.com/contact.php ==> https://example.com/contact/
現在, https: //example.com/contact/ URL應該從/contact.php加載內容。 我正在.htaccess下嘗試,但由於重定向循環而失敗。
RewriteEngine on
RewriteRule ^contact$ contact.php [NC,L]
RewriteCond %{REQUEST_URI} !^contact.php$
RewriteRule ^contact.php$ http://example.com/contact/ [R=301]
使用以下代碼刪除擴展
# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(one)/?$ /$1.php [L,NC]
請嘗試以下操作:
# It redirects the contact.php to /contact/, so .php extension is removed
RewriteRule ^contact\.php$ /contact/ [L,R=301]
# It fetches contact.php when /contact/ is requested by the user
RewriteRule ^/contact/$ /contact.php [L,NC]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.