需要有关 mod_rewrite 规则的帮助

发布于 2024-10-08 05:22:13 字数 300 浏览 0 评论 0原文

我正在使用 PHP 的 RouteMap 并希望清理该网址。

URL 的形式为:

http://localhost/subfolder/index.php?controller/method/arg1

我如何将其转换为:

http://localhost/subfolder/controller/method/arg1

I'm using PHP's RouteMap and want to clean up the URL.

The URL's come in the form of:

http://localhost/subfolder/index.php?controller/method/arg1

How would I convert this to:

http://localhost/subfolder/controller/method/arg1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

小糖芽 2024-10-15 05:22:13

还没有测试过,但我想你会想要以下内容:

 RewriteRule ^/subfolder/controller/(method/.*)$ /subfolder/index.php?controller/$1

haven't tested it, but I think you will want the following:

 RewriteRule ^/subfolder/controller/(method/.*)$ /subfolder/index.php?controller/$1
杀お生予夺 2024-10-15 05:22:13

您可以在 httpd.conf 文件中尝试此操作:

#start your engine
RewriteEngine on
#add www. for any url, not what you asked for, but kinda helpful SEO-wise
RewriteCond %{HTTP_HOST} ^mypage\.com
RewriteRule ^(.*)$ http://www.mypage.com$1
#rewrite stuff
RewriteRule ^/subfolder/(controller/method/arg1)/?$ /index.php?$1

应该可以。我会更改最后一行,但是:

RewriteRule ^/subfolder/(controller/method/arg1)/?$ /index.php?p=$1

现在,在重新启动 apache 之前,尝试测试配置文件是否正常。

user$ apachectl configtest

就是这样。

希望有帮助。

干杯

You can try this in your httpd.conf file:

#start your engine
RewriteEngine on
#add www. for any url, not what you asked for, but kinda helpful SEO-wise
RewriteCond %{HTTP_HOST} ^mypage\.com
RewriteRule ^(.*)$ http://www.mypage.com$1
#rewrite stuff
RewriteRule ^/subfolder/(controller/method/arg1)/?$ /index.php?$1

That should work. I would change the last line, tho:

RewriteRule ^/subfolder/(controller/method/arg1)/?$ /index.php?p=$1

Now, before you restart apache, try to test if the config file is ok.

user$ apachectl configtest

And that's about it.

Hope it helps.

Cheers

陪你搞怪i 2024-10-15 05:22:13
RewriteRule ^products/([0-9][0-9])/$ /productinfo.php?prodID=$1 [R]
RewriteRule ^products/([0-9][0-9])$ /products/$1/ 

可以按顺序应用同一 .htaccess 文件中的多个重定向,这就是它的作用

RewriteRule ^products/([0-9][0-9])/$ /productinfo.php?prodID=$1 [R]
RewriteRule ^products/([0-9][0-9])$ /products/$1/ 

Multiple redirects in the same .htaccess file can be applied in sequence, which is what this does

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文