我有一个URL,如下所示:
url.com/picture.php?id=51
我该如何将该URL转换为:
picture.php/Some-text-goes-here/51
我认为WordPress也是这样做的。
如何在PHP中创建友好的URL?
发布于 2013-05-06 05:01:46
这是一个将几乎所有内容都转发到index.php的.htaccess文件
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !-l
RewriteCond %{REQUEST_FILENAME} !\.(ico|css|png|jpg|gif|js)$ [NC]
# otherwise forward it to index.php
RewriteRule . index.php
然后由您解析$_SERVER"REQUEST_URI“并路由到picture.php或其他任何地方
发布于 2013-05-06 04:47:10
PHP不是您要找的,请查看mod_rewrite。
发布于 2017-04-27 14:44:23
虽然已经回答了,并且作者的意图是创建一个前端控制器类型的应用程序,但我发布了问题询问的文字规则。如果有人有同样的问题。
RewriteEngine On
RewriteRule ^([^/]+)/([^/]+)/([\d]+)$ $1?id=$3 [L]
上面应该适用于url picture.php/Some-text-goes-here/51
。而不使用index.php作为重定向应用程序。
https://stackoverflow.com/questions/16388959
复制相似问题