编写 SEO 友好 URL 的最有效方法?
我目前使用 .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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将整个查询字符串作为一个参数获取。
然后你可以用 php 分割字符串并将不同的参数转换为数组来执行你喜欢的操作。
You could get the whole query string as one paramter.
Then you can split the string with php and convert the different parameters into an array to do whatever you like with.
它被称为“路由器”。
请参阅 Zend Controller Router fe
It is called "router".
See Zend Controller Router f.e.