php - 如何编写干净的 url 我有两个来自不同文件夹的 url 第一个 url 来自根目录,另一个来自 root/tutorials/htaccess
问题描述
我有以下两个网址我想让它干净的网址
原始网址
https://www.evidhya.com/tutorials/get_data.php?qid=ADO
我想像这样清理网址
https://www.evidhya.com/tutorials/ADO
第二个网址是https://www.evidhya.com/tutorials/tutorials.php?qid=459
我想像这样清理网址https://www.evidhya.com/tutorials/459
我试过这些规则
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(\d+)/?$ tutorials.php?qid=$1 [L,QSA]
RewriteRule ^([\w.-]+)/?$ get_data.php?qid=$1 [L,QSA]
在上述规则的帮助下,我能够实现这样的干净网址
https://www.evidhya.com/tutorials/ADO
和
https://www.evidhya.com/tutorials/459
解决方案
/tutorials/
使用以下规则创建一个 .htaccess 内部目录:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(\d+)/?$ tutorials.php?qid=$1 [L,QSA]
RewriteRule ^([\w-]+)/?$ get_data.php?qid=$1 [L,QSA]
确保 中没有其他规则tutorials/.htaccess
。
现在在浏览器中加载这两个 URL 来测试:
https://www.evidhya.com/tutorials/ADO
https://www.evidhya.com/tutorials/459
推荐阅读
- python - 如何使用网格而不是包使我的 python 滚动条可滚动和画布自动调整大小
- linux - 在 bash case 语句中出现语法错误
- excel - 增加范围
- xslt - 如何比较同一组的兄弟姐妹?
- javascript - 我正在制作基于文本的 RPG,您可以在每个屏幕上说是或否,我需要帮助删除事件监听器
- javascript - 上传pdf文件时如何在浏览器中显示pdf
- php - 使用键值重定向 PHP url
- java - Spring批处理spring jpa错误CannotCreateTransactionException:无法为事务IllegalStateException打开JPA EntityManager:
- python - 如何修复 ray 不断增长的内存使用量?
- javascript - var 元素内部的随机数生成器每次调用时都会给出相同的输出