【发布时间】:2012-04-03 14:57:11
【问题描述】:
我希望用户能够使用$_SERVER['PATH_INFO'] 作为要提供的文件的占位符并删除地址栏中的 index.php
例如,我想为用户访问的任何 PATH_INFO 提供 me.com/index.php/settings1 为 me.com/settings1 等等。
如何将其写为 htaccess 规则?我什至不知道从哪里开始
如果有帮助,我正在使用 hostgator 的共享托管计划。
根据@EddyFreddy 的建议,我尝试了该问题中提到的两种方法,但没有成功。到目前为止,文件是这样的:
suPHP_ConfigPath /home/user/php.ini
<Files php.ini>
order allow,deny
deny from all
</Files>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.mysite.com$ [NC]
RewriteRule .? http://mysite.com%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L] # tried with and without the `?`
【问题讨论】:
-
看到这个[问题][1] [1]:stackoverflow.com/questions/4365129/…
-
@EddyFreddy:它不工作查看编辑
-
@EddyFreddy:经过进一步检查,我发现我不需要在地址栏中有
index.php,但如果是,我也希望将其删除那里。例如me.com/settings1有效,但我也希望me.com/index.php/settings1重定向到me.com/settings1
标签: php regex apache .htaccess mod-rewrite