如何设置友好的 URL

发布于 2024-10-03 21:42:19 字数 340 浏览 0 评论 0原文

我正在寻求您关于实现友好 URL 的最佳方式的建议。

我目前所做的是将所有 404 请求重定向到 index.php 中不存在的文件夹或文件。 index.php 读取查询字符串并进行数据库调用以查看该 url 是否在 page_urls 表中,然后根据页面类型获取内容等。

.htaccess 包含以下几行:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

有没有更“聪明”的“请问如何做到这一点?谢谢。

谢谢。

I am looking for your recommandations on what would be the best way to implement friendly URLs.

What I currently do is redirect all 404 requests to folders or files that do not exist to index.php.
index.php reads the query string and makes a database call to see if the url is in the page_urls table then based on the page type fetches content etc etc.

The .htaccess contains the following lines:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

Is there a more "clever" way of doing this please? Thank you.

Thank you.

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

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

发布评论

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

评论(1

沫雨熙 2024-10-10 21:42:19

我发现的最好的方法是执行如下操作:

RewriteEngine on 
RewriteRule ([a-zA-Z0-9_-]*)\.html index.php?page=$1 [L]

The best way I've found is to do something like the following:

RewriteEngine on 
RewriteRule ([a-zA-Z0-9_-]*)\.html index.php?page=$1 [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文