htaccess 不重定向
我有
www.mydomain.com/page_articles
一些链接,
www.mydomain.com/page_articles/some_article
但“some_article”是从php文件“load.php”渲染的,所以它看起来像:
www.mydomain.com/page_articles/load.php?page=some_article
我会在htaccess中放入什么,以便我可以拥有漂亮的链接?
我目前有:
RewriteEngine On
RewriteRule ^page_articles$ /page_articles/load.php?page=$1
RewriteRule ^page_articles/$ page_articles/load.php?page=$1
谢谢
i have
www.mydomain.com/page_articles
with links that would point to
www.mydomain.com/page_articles/some_article
but "some_article" get rendered from a php file "load.php" so it would look like:
www.mydomain.com/page_articles/load.php?page=some_article
What would i put in htaccess so that i can have pretty links?
I currently have:
RewriteEngine On
RewriteRule ^page_articles$ /page_articles/load.php?page=$1
RewriteRule ^page_articles/$ page_articles/load.php?page=$1
THanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在字符串中添加括号允许您在页面变量 $1 中使用“some _articles”,这是假设 page_articles 文件夹中有一个名为 load.php 的文件
Adding the brackets in the string allows you to use "some _articles" it the page variable $1, this is assuming there is a file called load.php in the page_articles folder
类似的事情应该有效。 (.) 将 / 之后的所有内容捕获到 $1 中。 . = 任意字符 0 次或多次。 RewriteCond 告诉 RewriteRule 如果匹配以 load.php 开头则忽略它(以避免无限循环)。问号表示可能有也可能没有尾随 /。
Something along the lines of this should work. The (.) captures whatever comes after the / into $1. . = any character 0 or more times. The RewriteCond is telling the RewriteRule ignore it if it the match starts with load.php (to avoid an infinite loop). The question mark indicates that there may or may not be a trailing /.