http.conf 将 example.com/foo/bar 重定向到 example.com/foo?id=bar

发布于 2024-12-03 20:08:03 字数 873 浏览 0 评论 0原文

我正在尝试创建一个动态页面,其内容由传递给它的变量确定,但我希望 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滴情不沾 2024-12-10 20:08:03

我在 httpd.conf 中使用它

<VirtualHost *:80>
    DocumentRoot "/var/www/"
    ServerName www.domain.com   
    ServerAlias www.domain.com
    <Directory /var/www/>
        #other directives
    </Directory>    
    <Directory /var/www/foo/>   
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d 
        RewriteRule ^([a-z]+)(\/?)$ index.php?id=$1 [NC,QSA,L]
    </Directory>
</VirtualHost>

I use this in my httpd.conf

<VirtualHost *:80>
    DocumentRoot "/var/www/"
    ServerName www.domain.com   
    ServerAlias www.domain.com
    <Directory /var/www/>
        #other directives
    </Directory>    
    <Directory /var/www/foo/>   
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d 
        RewriteRule ^([a-z]+)(\/?)$ index.php?id=$1 [NC,QSA,L]
    </Directory>
</VirtualHost>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文