的.htaccess和URL下探文件名 [英] .htaccess and dropping filename in URL

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

问题描述

目前我正在试图放弃从URL中的文件名(.PHP)在我的网站和碰到下面的.htaccess code:

I am currently trying to drop the filename (.php) from the URLs on my site and came across the following .htaccess code:

# Remove filename extension
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

我已经测试了这一点,它工作正常在我的网站。我有令人担忧的是该网站将获得超过10万次点击来自世界各地的...这将重写的.htaccess造成任何的过载到我的服务器?

I have tested this and it works correctly on my site. The concern I have is the site will receive 100,000+ hits from all over the world...will this .htaccess rewrite cause any overload to my server?

我是梅辛与自定义URL重写在.htaccess几个月前,在另一个项目,它一直在超载服务器上的内存。

I was messing with custom URL rewrites in .htaccess a few months back, on another project and it kept overloading the memory on the server.

有没有办法来保护这种情况的发生,或这是一个非问题,这种类型的改写在.htaccess?

Is there a way to protect this from happening or is this a non-issue with this type of rewrite in .htaccess?

推荐答案

阅读上的贪婪和懒惰普通防爆pression。你重写规则的第一部分是懒惰的(这是比贪婪更);但它仍然是细化不够确切地知道它的寻找。

Read up on "greedy" and "lazy" Regular Expression. The First segment of your RewriteRule is lazy (which is better than greedy); however it is still refined enough to know exactly what it's looking for.

贪婪将需要显著量的存储器。你可能希望把它 [QSA,NC,L]

Greedy would require a significant amount of memory. You might want to make it [QSA,NC,L].

QSA会添加任何?查询=字符串,数控强制链接直接忽略的情况下,和L表示这是最后重写规则来检查,直到下一个重写条件。

QSA will add any ?query=strings, the NC forces the url to ignore the case, and L means it's the last rewrite rule to check until the next rewrite condition.

结束语在IFModule是pretty的重要,如果重写工作不正常不希望服务器500错误。该的RewriteBase会告诉它把它从.htaccess文件是坐在文件夹的根文件After的追捧。

Wrapping it in a IFModule is pretty important, don't want server 500 errors if Rewrite isn't working right. The RewriteBase will tell it to get it's sought after files from the root of the folder the .htaccess file is sitting in.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^([^\.]+)$ $1.php [QSA,NC,L]
</IfModule>

这篇关于的.htaccess和URL下探文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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