简体   繁体   中英

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.

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:

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] 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM