的.htaccess删除文件扩展名不工作 [英] .htaccess to remove file extension not working

查看:185
本文介绍了的.htaccess删除文件扩展名不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在那里的一些文件和文件夹存储公共HTML文件夹中。然后,我创建了一个文件夹在里面。该文件夹中包含了一些文件和文件夹管理,这containes与我的管理面板文件浏览我的网站成员的数据。

现在我用以下code。在.htaccess文件中删除所有页面的PHP extension.But当我尝试登录到我的管理面板公共HTML文件夹,登录失败。

例如。 www.abc.com >>这里的.htaccess文件是以下code。

它适用于文件中的 www.abc.com ,并在 www.abc.com/xyz/index.php 等文件的文件。但是当使用时 www.abc.com/xyz/admin/index.php :用于登录,这个页面只得到刷新,但不会允许登录成功。

在.htaccess中使用code是如下:

  RewriteEngine叙述上

的RewriteCond%{THE_REQUEST} \ S / +(?:指数)?(。*?)\ PHP [\ S?] [NC]
重写规则^ /%1 [R = 301,L,NE]

的RewriteCond%{} THE_REQUEST /指数[NC]
重写规则^(?*)指数([/] | $)/ $ 1 [L,R = 302,NC,NE]

的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{DOCUMENT_ROOT} / $ 1.PHP -f [NC]
重写规则^(。+?)/?$ /$1.php [L]
 

解决方案

尝试这些规则,避免重定向的 POST 请求:

  RewriteEngine叙述上

的RewriteCond%{REQUEST_METHOD}!POST
的RewriteCond%{THE_REQUEST} \ S / +(?:指数)\?(*?)。(?:PHP | HTML)?\ s]的[NC]
重写规则^ /%1 [R = 301,L,NE]

的RewriteCond%{REQUEST_METHOD}!POST
的RewriteCond%{} THE_REQUEST /指数[NC]
重写规则^(?*)指数([/] | $)/ $ 1 [L,R = 302,NC,NE]

的RewriteCond%{} REQUEST_FILENAME -f [OR]
的RewriteCond%{} REQUEST_FILENAME -d
重写规则^  -  [L]

的RewriteCond%{DOCUMENT_ROOT} / $ 1.PHP -f [NC]
重写规则^(。+?)/?$ /$1.php [L]

的RewriteCond%{DOCUMENT_ROOT} / $ 1.HTML -f [NC]
重写规则^(。+?)/?$ /$1.html [L]
 

I have public html folder where some files and folders are stored. Then I have created a Folder In It. That Folder Contains Some Files And A Folder "Admin" which containes files related to my admin panel to surf my site members data.

Now I used Following Code In .htaccess file in public html folder which removes all pages's php extension.But When I try To Log In To My Admin Panel, Log In Fails.

e.g. www.abc.com >> Here .htaccess file Is with following code.

It works For Files in www.abc.com and for files in www.abc.com/xyz/index.php and other files. But When Tried www.abc.com/xyz/admin/index.php For Login, This Page just get refreshed But Doesn't allowing successful login.

Code used in .htaccess is as follows :

RewriteEngine On  

RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

RewriteCond %{THE_REQUEST} /index [NC]
RewriteRule ^(.*?)index([/.]|$) /$1 [L,R=302,NC,NE]

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

解决方案

Try these rules that avoid redirecting for POST requests:

RewriteEngine On  

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.(?:php|html)[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /index [NC]
RewriteRule ^(.*?)index([/.]|$) /$1 [L,R=302,NC,NE]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]

RewriteCond %{DOCUMENT_ROOT}/$1.html -f [NC]
RewriteRule ^(.+?)/?$ /$1.html [L]

这篇关于的.htaccess删除文件扩展名不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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