htaccess的隐藏扩展名和变量 [英] .htaccess hide extension and variables

查看:216
本文介绍了htaccess的隐藏扩展名和变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何隐藏文件的扩展名,并通过在的.htaccess一行中得到变量?这code不工作。

How can I hide the file's extension and the get variables via .htaccess in one line? This code doesn't works.

...
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^file-([0-9]+)\.php$ /some_directory/files.php?id=$1 [L]

例如:

http://www.mysite.com/file.php?variable=value

应该是:

http://www.mysite.com/file

推荐答案

您需要添加一些条件,第一条规则,以保持它的循环,你可以尝试将其更改为:

You need to add a few conditions to the first rule to keep it from looping, you can try changing it to:

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

然后去继续你的第二个规则,细loks事情是这样的。

Then go continue with your second rule, which loks fine the way it is.

这篇关于htaccess的隐藏扩展名和变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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