now*_*iko 11 php apache .htaccess mod-rewrite url-rewriting
前言:是的,这个问题似乎是重复的,我找到了相关问题,但那里的答案对我没有帮助.:(
您好,我想为我的PHP项目添加人类可读URL的支持.现在我的URL问号字符串如下所示:
index.php?url=main/index
Run Code Online (Sandbox Code Playgroud)
我想让它看起来像:
index.php/main/index
Run Code Online (Sandbox Code Playgroud)
我读了以下文章:
但是当我这样做时:
var_dump($_GET['url']); // get empty array
Run Code Online (Sandbox Code Playgroud)
,获取空数组,如没有添加url参数.
我目前.htaccess:
DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php?url=$1 [NC]
Run Code Online (Sandbox Code Playgroud)
有人可以帮帮我吗?谢谢!
网址: http://domain.com/index.php/controller/action
重写的网址: http://domain.com/index.php?url=controller/action
.htaccess
DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index.php/(.*)$ /index.php?url=$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)
说明:
该.*图案中的^index.php/(.*)$一切后,匹配index.php/于输入URL.括号有助于将零件捕获为变量$1,然后在替换URL /index.php?url=+ 的末尾添加$1.
[L, QSA]:L忽略其他重写规则,如果这适合.QSA表示查询字符串追加.