繁体   English   中英

使用mod_rewrite规则将所有路径映射到index.php

[英]A mod_rewrite rule to map all paths to index.php

我在www.mydomain.com/mydirectory/index.php上有一个脚本。 我想将所有请求映射到脚本的mydirectories的子目录。 例如,应该将www.mydomain.com/mydirectory/mypath/重写为www.mydomain.com/mydirectory/index.php/mypath/

我该怎么做? 谢谢。

mydirectory目录的.htaccess文件中尝试以下操作:

RewriteEngine on
RewriteCond $0 !^index\.php/
RewriteRule .* index.php/$0 [L]

如果所请求的文件或文件夹不存在,这会将所有请求转发到index.php

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

例如, http://www.example.com/category/5/变为http://www.example.com/index.php/category/5/

您可以使用explode()和$ HTTP_SERVER_VARS来解析index.php后面的路径

$url = explode('/', $HTTP_SERVER_VARS['PATH_INFO']);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM