[英]htaccess mod_rewrite - direct specific multi pages to one page and deny access to files with extensions
I would need your help to write htaccess file in order to 1) redirect specific pages with urls like below to one page and 2) also deny access to the pages with extension like php. 我将需要您的帮助来编写htaccess文件,以便1)将具有以下url的特定页面重定向到一页,以及2)还拒绝访问具有php扩展名的页面。
1)
www.example.com/index --> www.example.com
www.example.com/about --> www.example.com
www.example.com/contact --> www.example.com
2)
not found
www.example.com/index.php
www.example.com/about.php
www.example.com/contact.php
3)
be found
www.example.com/index
www.example.com/admin
thanks Ramin 谢谢拉明
You can use this code in your DOCUMENT_ROOT/.htaccess
file: 您可以在
DOCUMENT_ROOT/.htaccess
文件中使用以下代码:
RewriteEngine On
RewriteRule ^(index|about|contact)/?$ / [NC,L,R=302]
RewriteCond %{THE_REQUEST} \.php [NC]
RewriteRule \.php$ - [L,R=404]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+)/?$ $1.php [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /dolarfori/index.php?path=$1 [NC,L,QSA]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.