这个标题几乎总结了它。我试图隐藏index.php,但任何其他php文件,如file.php将成为/ file / etc ......
到目前为止,我有这个htaccess,但它不起作用......
Options -Indexes -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
任何人都可以帮我吗?
感谢。
答案 0 :(得分:0)
隐藏index.php
的最佳方式是永远不要链接到它,这不是必需的,我不知道为什么人们会这样做。使用/
中的href
链接到网络根目录,或./
链接到当前目录。
# 404.php file should set status with header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
ErrorDocument 404 /404.php
Options -Indexes -Multiviews
RewriteEngine On
RewriteBase /
# remove .php from legitimate requests (you should still update all the URLs served so that normal crawling/browsing doesn't 301 on every link)
RewriteCond %{THE_REQUEST} ^\S++\s++((/[^?\s]+?)??/index\.php)(\?\S*+)?\s [OR]
RewriteCond %{THE_REQUEST} ^\S++\s++((/[^?\s]+?)\.php)(\?\S*+)?\s
RewriteCond %{DOCUMENT_ROOT}%1 -f
RewriteRule ^ %2/%3 [NS,NE,L,R=301]
# add trailing / to legitimate requests missing it
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .+ $0/ [NS,NE,L,R=301]
# rewrite all requests that look like directories to files, /foo/ to /foo.php and /bar/baz/qux/ to /bar/baz/qux.php
RewriteCond %{DOCUMENT_ROOT}$1.php -f
RewriteRule ^([^./][^/]*+(?:/[^./][^/]*+)*)/$ $1.php [NS,L,DPI]
# allow everything else to be processed as normal file request or 404