有关我的地盘我有一个重写规则指向的网址 www.mysite/work到work.php文件。我也有称为目录工作,有它的文件,像project1.php,project2.php,等等...
For my site I have a RewriteRule that points the URL www.mysite/work to a work.php file. I also have a directory called "work" that has files in it, like project1.php, project2.php, etc...
什么规则,我会写这样的网址 www.mysite/work知道去到work.php文件,但URL www.mysite/工作/ PROJECT1 知道我的意思是里面去的目录工作并显示project1.php文件?
What rules would I have to write so that the URL www.mysite/work knows to go to the work.php file, but the URL www.mysite/work/project1 knows I mean to go inside the directory "work" and display the project1.php file?
修改:应该指出,这是我目前正在使用:
EDIT: Should point out, this is what I'm currently working with:
RewriteEngine On RewriteBase /beta/ RewriteRule ^([a-z]+)$ $1.php [L]
任何额外的提示,以改善这种安全明智? (停止目录跳跃,等...)
Any additional tips to improve this security-wise? (Stopping directory jumping, etc...)
推荐答案试试这个:
RewriteEngin On RewriteBase / RewriteRule ^work$ /work.php [QSA,L]这将确保 www.mysite/work (没有尾随斜线)将转到 work.php 文件。
That will ensure that www.mysite/work (no trailing slash) will go to your work.php file.
如果您还想 www.mysite/work/ (带斜线)去 work.php 添加此行略高于去年重写规则。
If you also want www.mysite/work/ (with trailing slash) to go work.php, add this line just above the last RewriteRule.
RewriteRule ^work/$ /work [R=301,QSA,L]这会重定向到没有结尾的斜线的网址,因此,显示 work.php 文件。
That will redirect it to the URL with no trailing slash thus, displaying the work.php file.
更新:既然你已经有一个的RewriteBase 指令,只是把重写规则行之后(S)你的的RewriteBase 但你的前重写规则作为规则你使用一个包罗万象的和会匹配一切。
UPDATE: Since you already have a RewriteBase directive, just put the RewriteRule line(s) right after your RewriteBase but before your RewriteRule as the rule you're using a catch-all and will match everything.
更多推荐
的.htaccess重写URL页或目录
发布评论