htaccess的删除的.php和.html和斜杠 [英] htaccess remove .php, .html and trailing slash

查看:264
本文介绍了htaccess的删除的.php和.html和斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图删除的.php的.html和使用的htaccess的URL traling斜线,怎么过这个code工作正常,为PHP而不是HTML和斜线

有关PHP

 的RewriteCond%{THE_REQUEST} ^ GET。*指数\ .PHP [NC]
的RewriteCond%{REQUEST_URI}!/系统/.* [NC]
重写规则(。*?)指数\ .PHP /*(.*)/ $ 1 $ 2 [R = 301,NE,L]
#指示通过该网站的索引文件中的所有EE Web请求
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$ /index.php/$1 [L]
 

有关HTML

 的RewriteCond%{REQUEST_URI}的index.html
重写规则^(。*)的index.html $ / 1 $ / [R = 301,L]
 

解决方案

有这样说道:

 #删除斜杠
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{THE_REQUEST} \ S(。+?)/ +?\ S]
重写规则^(。+?)/ $ / $ 1 [R = 301,L]

#删除PHP / HTML扩展
的RewriteCond%{} THE_REQUEST /index\.(php|html)[\s/?] [NC]
的RewriteCond%{REQUEST_URI}!/系统/ [NC]
重写规则^指数\(*?)。(?:PHP | HTML)$ $ 1 $ 2 [R = 301,NE,L](*)。

#内部添加php扩展
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{DOCUMENT_ROOT} / $ 1.PHP -f
重写规则^(。+?)/?$ /$1.php [L]

#内部添加HTML扩展
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{DOCUMENT_ROOT} / $ 1.HTML -f
重写规则^(。+?)/?$ /$1.html [L]
 

i am trying to remove .php .html and traling slash from url using htaccess,how ever this code working fine for php but not for html and trailing slash

For PHP

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

For HTML

RewriteCond %{REQUEST_URI} index.html
RewriteRule ^(.*)index.html$ /$1/ [R=301,L]

解决方案

Have it this way:

# remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L]

# remove php/html extension
RewriteCond %{THE_REQUEST} /index\.(php|html)[\s/?] [NC]
RewriteCond %{REQUEST_URI} !/system/ [NC]
RewriteRule ^(.*?)index\.(?:php|html)(.*)$ $1$2 [R=301,NE,L]

# internally add php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]

# internally add html extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(.+?)/?$ /$1.html [L]

这篇关于htaccess的删除的.php和.html和斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆