http.conf 将 example.com/foo/bar 重定向到 example.com/foo?id=bar
我正在尝试创建一个动态页面,其内容由传递给它的变量确定,但我希望 url 很好。基本上我想在目录 /foo 中有一个处理任何栏的索引文件。 example.com/foo/bar 到 example.com/foo?id=bar
我已经在 httpd.conf 文件中尝试了我能想到的一切。我最近的尝试是:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/foo/([a-z-]*) /foo/index.php?id=$1 [QSA,L]
但是,当我尝试加载 example.com/foo/bar 时,加载的页面是 example.com
非常感谢任何帮助!
编辑:当我访问 example.com/foo/bar 时,它仍在加载 example.com/index.php 也许我的其他规则之一正在干扰?
AllowOverride none
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)\.html$ http://www.example.com/$1.php [R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/foo/([a-z-]*)(\/?)$ /foo/index.php?id=$1 [NC,QSA,L]
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^/?(.*) http://www.example.com/$1 [L,R,NE]
.html 到 .php,我想要实现的目标,以及 example.com 到 www.example.com 分别。
I am trying to create a dynamic page who's contents are determined by a variable passed to it, but I want the url to be nice. Basically I want to have a single index file in the directory /foo that handles any bar. example.com/foo/bar to example.com/foo?id=bar
I have tried everything I can think of in my httpd.conf file. My latest try was:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/foo/([a-z-]*) /foo/index.php?id=$1 [QSA,L]
However when I try to load example.com/foo/bar the page that loads is example.com
Any help is much appreciated!
Edit: It's still loading example.com/index.php when I visit example.com/foo/bar Maybe one of my other rules is interfering?
AllowOverride none
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)\.html$ http://www.example.com/$1.php [R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/foo/([a-z-]*)(\/?)$ /foo/index.php?id=$1 [NC,QSA,L]
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^/?(.*) http://www.example.com/$1 [L,R,NE]
.html to .php, what I'm trying to achieve, and example.com to www.example.com respectively.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 httpd.conf 中使用它
I use this in my httpd.conf