【发布时间】:2020-08-25 16:49:44
【问题描述】:
我正在开发一个网站,我需要在其中创建一个特定的 URL 结构......那么如何制作这个 url:
http://example.com/index.php?city=mumbai&place=chembur
进入这个:
http://example.com/mumbai/chembur
有可能吗?
编辑:
我尝试在 htaccess 文件中使用以下代码,但它显示一个空页面
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteRule !/$ %{REQUEST_URI}/ [L,R=301]
# RewriteCond %{REQUEST_FILENAME} -f [OR]
# RewriteCond %{REQUEST_FILENAME} -d
# RewriteRule ^ - [L]
# RewriteRule ^([^/]+)/([^/]+)/?$ index.php?city=$1&place=$2 [L,QSA]
# RewriteRule ^([^/]+)/?$ index.php?city=$1 [L,QSA]
编辑:我选择@AbsoluteBeginner 答案是因为它的代码更少且错误为 0。我知道这不是 url 重定向,但它正在解决我的问题。
另外,感谢@CallofDev 提供的这么多帮助!
【问题讨论】:
-
@Evert 我已经编辑了我的问题
-
@anubhava 是的,我测试了 .htaccess 已启用
标签: php .htaccess mod-rewrite