的.htaccess重写URL页或目录

编程入门 行业动态 更新时间:2024-10-22 14:44:20
本文介绍了的.htaccess重写URL页或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有关我的地盘我有一个重写规则指向的网址 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页或目录

本文发布于:2023-11-01 20:17:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550310.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   目录   htaccess   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!