编写 SEO 友好 URL 的最有效方法?

发布于 2024-12-27 19:38:59 字数 670 浏览 4 评论 0原文

我目前使用 .htaccess 和 PHP 按以下方式解析 URL:

URL:

http://blah.com/article/123_this-that-and-the-other

.htaccess:

RewriteEngine On
RewriteRule ^article/([0-9]+)_(.+)/?$   index.php?page=article&id=$1 [L]

PHP

$page = isset($_GET['page']) ? safeGET($_GET['page']) : null;
$id   = isset($_GET['id'])   ? safeGET($_GET['id'])   : null;
if ($page=='article') { include 'article.php'; } elseif { ... }

我已经开始遇到问题过于偏执的 Mod_Security 引擎不喜欢我的 $_GET 请求中的“admin”一词。但大多数情况下,我只是在寻找解析 SEO 友好 URL 的新技术。

有人知道更优雅的方法吗?

I currently use .htaccess and PHP to parse URLs in the following way:

URL:

http://blah.com/article/123_this-that-and-the-other

.htaccess:

RewriteEngine On
RewriteRule ^article/([0-9]+)_(.+)/?$   index.php?page=article&id=$1 [L]

PHP

$page = isset($_GET['page']) ? safeGET($_GET['page']) : null;
$id   = isset($_GET['id'])   ? safeGET($_GET['id'])   : null;
if ($page=='article') { include 'article.php'; } elseif { ... }

I've begun running into problems with the far-too-paranoid Mod_Security engine that doesn't like the word "admin" in my $_GET requests. But mostly I'm just looking for new techniques for parsing SEO friendly URLs.

Anyone know of a more elegant approach?

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

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

发布评论

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

评论(2

柳絮泡泡 2025-01-03 19:38:59

您可以将整个查询字符串作为一个参数获取。

RewriteRule ^([^.]+)$ index.php?url=$1 [QSA,L]

然后你可以用 php 分割字符串并将不同的参数转换为数组来执行你喜欢的操作。

You could get the whole query string as one paramter.

RewriteRule ^([^.]+)$ index.php?url=$1 [QSA,L]

Then you can split the string with php and convert the different parameters into an array to do whatever you like with.

心如狂蝶 2025-01-03 19:38:59

它被称为“路由器”。

请参阅 Zend Controller Router fe

It is called "router".

See Zend Controller Router f.e.

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