mod_rewrite:帮助重写 URL

发布于 2024-12-26 04:55:19 字数 542 浏览 1 评论 0原文

我有一个网站,我正在尝试重写它的网址。

这很简单,但我不明白该怎么做。

页面如下:

http://localhost/site/index.php?p=home等。home是一个参数,重写应该是这样的:http:// /localhost/site/home.html

http://localhost/site/section.php?id=someid 我希望它像 http://localhost/站点/来自数据库 SOMEID 的部分名称

http://localhost/site/product.php?id=someid 我希望它像 http://localhost/site/category-name/product-name-SOMEID< /strong>

我认为这很简单,但我仍然不明白该怎么做。请帮我。

谢谢!

I have a website and I'm trying to rewrite it's url.

It's pretty simple, but i'm not understanding how to do it.

The pages are the next ones:

http://localhost/site/index.php?p=home, etc. home is a parameter, and rewrite should be like this: http://localhost/site/home.html

http://localhost/site/section.php?id=someid and i want it to be like http://localhost/site/the-name-of-the-section-from-database-SOMEID

http://localhost/site/product.php?id=someid and i want it to be like http://localhost/site/category-name/product-name-SOMEID

I think it's simple, but I still don't understand how to do it. Please, help me.

Thanks!

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

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

发布评论

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

评论(3

温柔戏命师 2025-01-02 04:55:20

http://net.tutsplus.com/教程/其他/a-deeper-look-at-mod_rewrite-for-apache/
使用此链接有关于 mod_rewrite 的详细说明。而且我认为 anubhava 的正则表达式是正确的

http://net.tutsplus.com/tutorials/other/a-deeper-look-at-mod_rewrite-for-apache/
use this link in has a detail ehplanation about mod_rewrite.also i think anubhava got the regex right

独夜无伴 2025-01-02 04:55:19

将这些行放入您的 ROOT .htaccess 中:

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteRule ^site/(home)\.html/?$ site/index.php?p=$1 [L,QSA,NC]

# Assuming hyphen is not in the section name
RewriteRule ^site/.*-(.*)/?$ site/section.php?id=$1 [L,QSA,NC]

# Assuming hyphen is not in the product name
RewriteRule ^site/[^/]*/.*-(.*)/?$ site/product.php?id=$1 [L,QSA,NC]

Put these lines in your ROOT .htaccess:

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteRule ^site/(home)\.html/?$ site/index.php?p=$1 [L,QSA,NC]

# Assuming hyphen is not in the section name
RewriteRule ^site/.*-(.*)/?$ site/section.php?id=$1 [L,QSA,NC]

# Assuming hyphen is not in the product name
RewriteRule ^site/[^/]*/.*-(.*)/?$ site/product.php?id=$1 [L,QSA,NC]
情深如许 2025-01-02 04:55:19

此页面应该可以帮助您.htaccess 网址重写生成器。它会为您生成 htaccess 文件。

this page shoul help you .htaccess Url Rewrite Generator. it generates htaccess files for you.

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