[英]How do I URL Rewrite for below situation?
I have a web page at following url. 我在以下网址处有一个网页。
https://example.com/contact.php https://example.com/contact.php
Now I want to configure the URL redirect like. 现在我要配置URL重定向之类的。 If user open page with complete URL, it should remove .php from URL automatically.
如果用户打开的页面具有完整的URL,则应自动从URL中删除.php。
https://example.com/contact.php ==> https://example.com/contact/ https://example.com/contact.php ==> https://example.com/contact/
Now the https://example.com/contact/ URL should load content from /contact.php. 现在, https: //example.com/contact/ URL应该从/contact.php加载内容。 I am trying below .htaccess but it failed with a redirect loop.
我正在.htaccess下尝试,但由于重定向循环而失败。
RewriteEngine on
RewriteRule ^contact$ contact.php [NC,L]
RewriteCond %{REQUEST_URI} !^contact.php$
RewriteRule ^contact.php$ http://example.com/contact/ [R=301]
Use the below code for remove the extention 使用以下代码删除扩展
# 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]
Try the following: 请尝试以下操作:
# 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.