Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP url重写?_Php_Url Rewriting - Fatal编程技术网

PHP url重写?

PHP url重写?,php,url-rewriting,Php,Url Rewriting,我的url类似于: http://.../user.php?do=login 使用PHP我想让它看起来像: http://.../user/login/ 我该怎么办?大多数地方似乎都在谈论.htaccess,但我无法访问其中的一个 谢谢。 创建一个.htaccess文件并写入 RewriteRule ^(.*)$ user.php?url=$1 [L,QSA] 正如其他人所说,只需使用像/index.php/nice/looking/url这样的链接即可。 URL中间的“index .ph

我的url类似于:

http://.../user.php?do=login
使用PHP我想让它看起来像:

http://.../user/login/
我该怎么办?大多数地方似乎都在谈论.htaccess,但我无法访问其中的一个

谢谢。

创建一个.htaccess文件并写入

RewriteRule ^(.*)$ user.php?url=$1 [L,QSA]

正如其他人所说,只需使用像
/index.php/nice/looking/url
这样的链接即可。 URL中间的“index .php”可能看起来有点奇怪,但我认为没有HTTAccess

不可能让它看起来更好。 否则,您可以要求宿主将任何URL重定向到/index.php,这样您就可以在URL中不包含
/index.php
的情况下处理URL重写

然后,您可以使用正则表达式匹配来检测要包含的文件。
preg_match('@[/]{1}([a-zA-Z0-9]+)@',$\u服务器[“路径信息”],$matches)
($matches将在数组中包含url的所有“部分”)

小心包含文件,使用白名单,这样你就可以确保没有人能够加载内部文件


source

如果您不能修改服务器设置,甚至不能使用htaccess,那么这将是一项艰巨的任务。PHP本身不重写url,这是web服务器做的这会有帮助,但你不会通过mod_重写得到漂亮的url,你能提供更多关于为什么你不能访问.htaccess文件的详细信息吗?如果你是共享主机,你可以在你的webroot文件夹中创建一个,这会有帮助吗[URL在PHP中重写而不使用htaccess][1][1]:“大多数地方似乎都在谈论.htaccess,我没有访问权限。”如果您有ftp或ssh访问权限,那么.htaccess文件可以放在文档根目录中,其中是您的index.PHP(或项目中的任何其他目录),如果它不在那里,您可以简单地创建它,请注意.htaccess是不可见的,因此可能需要为您的文件管理程序进行其他设置。如果您确实没有ftp访问权限,则应按如下方式重命名您的文件:for urlhttp://.../user/login 将有目录/user/login/index.php
。必须启用htaccess
简单地创建文件也许你很幸运,但OP似乎不是。(请参阅
AllowOverride