htaccess的删除的.php和.html和斜杠斜杠、htaccess、php、html

2023-09-02 11:25:48 作者:小妞、来啵个

我试图删除的.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]
 
php中的.htaccess伪静态

解决方案

有这样说道:

 #删除斜杠
的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]

 
精彩推荐
图片推荐