htaccess 删除并禁止所有扩展并添加 / 到 URL 的末尾
htaccess delete and ban all extensions and add / to the end of the URL
我正在 php 制作一个小 cms。通过 htaccess 我想删除并阻止所有扩展名(.php .html.htm 等)并在 url 末尾添加一个 /。
前任。 www.miosito/文章名称/
Options -Indexes
DirectoryIndex home.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ core.php
这是我当前的 htaccess。
抱歉我的英语不好,非常感谢你
根据您显示的 samples/attempts,您能否尝试遵循 htaccess 规则文件。请确保在测试您的网址之前清除浏览器缓存。
RewriteEngine ON
##Excluding Indexes and MultiViews options here.
Options -Indexes -MultiViews
##Rule for url http://localhost:80/test here.
RewriteRule ^(test)/?$ /category [R=301,L]
RewriteRule ^(test/category)/?$ .php [NC,L]
##Rule for forbidding html OR htm OR php extension files.
RewriteRule \.(html|php|Htm)/?$ - [F,NC,L]
##Rule for adding / at end of urls.
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
##Rules for non-existing pages to be served here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ core.php [QSA,L]
完全清除浏览器缓存后,在站点根目录 .htaccess 中尝试此代码:
Options -Indexes
DirectoryIndex home.php
RewriteEngine On
# block direct access to .php, .html, .html extensions files
RewriteCond %{THE_REQUEST} \.(html?|php)[?\s/] [NC]
RewriteRule . - [F]
## Adding a trailing slash
RewriteCond %{ENV:REDIRECT_STATUS ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,NE,R=301]
# core handler
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . core.php [L]
我正在 php 制作一个小 cms。通过 htaccess 我想删除并阻止所有扩展名(.php .html.htm 等)并在 url 末尾添加一个 /。 前任。 www.miosito/文章名称/
Options -Indexes
DirectoryIndex home.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ core.php
这是我当前的 htaccess。 抱歉我的英语不好,非常感谢你
根据您显示的 samples/attempts,您能否尝试遵循 htaccess 规则文件。请确保在测试您的网址之前清除浏览器缓存。
RewriteEngine ON
##Excluding Indexes and MultiViews options here.
Options -Indexes -MultiViews
##Rule for url http://localhost:80/test here.
RewriteRule ^(test)/?$ /category [R=301,L]
RewriteRule ^(test/category)/?$ .php [NC,L]
##Rule for forbidding html OR htm OR php extension files.
RewriteRule \.(html|php|Htm)/?$ - [F,NC,L]
##Rule for adding / at end of urls.
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
##Rules for non-existing pages to be served here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ core.php [QSA,L]
完全清除浏览器缓存后,在站点根目录 .htaccess 中尝试此代码:
Options -Indexes
DirectoryIndex home.php
RewriteEngine On
# block direct access to .php, .html, .html extensions files
RewriteCond %{THE_REQUEST} \.(html?|php)[?\s/] [NC]
RewriteRule . - [F]
## Adding a trailing slash
RewriteCond %{ENV:REDIRECT_STATUS ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,NE,R=301]
# core handler
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . core.php [L]