简体   繁体   English

如何修复.htaccess问题

[英]How to fix .htaccess problems

What I am trying to do it simple: 我正在尝试做的简单:

I want to remove .php extension from file for which I am using following code and it is working 我想从正在使用以下代码的文件中删除.php扩展名,并且该文件正在运行

#for hiding.php extension
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1\.php
############################-------- END ---------########################

Also I want to show a $_GET parameter on screen for which the link should be link this localhost/123 which is representation of localhost/somepage.php?para=123 and for which I am using following code which is also working fine 我也想在屏幕上显示一个$ _GET参数,该参数的链接应该是链接此localhost / 123,它表示localhost / somepage.php?para = 123,并且我正在使用以下代码,该代码也可以正常工作

    #for parameter Display
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*)$ somepage.php?para=$1
    ############################-------- END ---------########################

Problem: These codes are working fine when not written together in same `.htaccess` file. 问题:如果不在同一`.htaccess`文件中一起编写这些代码,则它们工作正常。 But when written together and When I have to access login page using localhost/login. 但是当一起写时,以及当我必须使用localhost / login访问登录页面时。 .htaccess treat login as get parameter value. .htaccess将登录视为获取参数值。 Any solution to this problem? 这个问题有什么解决办法吗?

Try this code: 试试这个代码:

RewriteEngine On

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ somepage.php?para=$1 [L,QSA]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM