htaccess重定向删除index.php

qwe*_*ymk 3 php regex apache .htaccess mod-rewrite

我希望用户能够$_SERVER['PATH_INFO']用作占位符来处理哪个文件并在地址栏中删除index.php

例如,我想服务me.com/index.php/settings1作为me.com/settings1等为用户去任何PATH_INFO.

我怎么写这个作为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 `?`
Run Code Online (Sandbox Code Playgroud)

anu*_*ava 8

这可以通过mod_rewrite轻松处理.在DOCUMENT_ROOT下的.htaccess中使用此代码:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# external redirect from /index.php/foo to /foo/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php(/[^\s\?]+)? [NC]
RewriteRule ^ %1/ [L,R]

# external redirect to add trailing slash
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+((?!.+/[\s\?])[^\s\?]+) [NC]
RewriteRule ^ %1/ [L,R]

# internal forward from /foo to /index.php/foo
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ index.php%{REQUEST_URI} [L,NC]
Run Code Online (Sandbox Code Playgroud)

验证一切正常后再更改RR=301.