Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.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
htaccess重定向以删除index.php_Php_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

htaccess重定向以删除index.php

htaccess重定向以删除index.php,php,regex,apache,.htaccess,mod-rewrite,Php,Regex,Apache,.htaccess,Mod Rewrite,我希望用户能够使用$\u SERVER['PATH\u INFO']作为文件的占位符,并在地址栏中删除index.php 例如,我想将me.com/index.php/settings1作为me.com/settings1等服务于用户访问的任何路径信息 我如何将其作为htaccess规则编写?我甚至不知道从哪里开始 如果有帮助的话,我正在hostgator的共享托管计划中 基于@EddyFreddy的建议,我尝试了问题中提到的两种方法,但都没有成功。以下是到目前为止该文件的外观: suPHP_C

我希望用户能够使用
$\u SERVER['PATH\u INFO']
作为文件的占位符,并在地址栏中删除index.php

例如,我想将
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 `?`
suPHP\u ConfigPath/home/user/php.ini
命令允许,拒绝
全盘否定
重新启动发动机
重写基/
RewriteCond%{HTTP_HOST}^www.mysite.com$[NC]
重写规则。?http://mysite.com%{REQUEST_URI}[R=301,L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
RewriteRule^(.*)$/index.php/$1[L]#是否使用``

经过长期评估,我发现anubhava的版本并非在所有情况下都适用于我。所以我尝试了这个修改版本。它将正确处理现有目录中的现有文件,并且不会产生双斜杠

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

###### Add trailing slash (optional) ######
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ $1/ [R=301,L]

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

###### internal forward from /foo to /index.php/foo ######
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ index.php%{REQUEST_URI} [L]

这可以通过mod_重写轻松处理。在文档根目录下的.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]

确认一切正常后,将
R
更改为
R=301

查看此[问题][1][1]:@EddyFreddy:它不工作,请参见edit@EddyFreddy:进一步检查后,我发现我不需要地址栏中有
index.php
,但如果有,我还希望将其删除。例如,
me.com/settings1
可以工作,但我也希望
me.com/index.php/settings1
重定向到
me.com/settings1
我是否应该足够在意人们链接到index.php会影响我的排名?我会忽略
index.php/settings1
重定向到
/settings1
-这只会让我感到困惑如果您想将旧的Pagerank恢复为新的URL,请注意。这似乎很难。也许你应该看看不同的操作系统,看看它们是如何做到的。@qwertymk你是在使用codeignetter或zend这样的框架,还是想构建自己的解决方案?@qwertymk这太快了,太脏了。我建议您使用Zend或CodeIgniter之类的框架——它们在快速构建网站和应用程序方面做得很好,并且有很好的使用ajax的方法。对我来说,这很有效,但是
http://localhost/index.php
未重定向到
http://localhost/
@EddyFreddy:我不确定OP是否想重定向
http://localhost/index.php
不过现在我做了一个编辑,也会处理这个边缘案例。太棒了,我总是在想,用神秘的表达式可以做什么疯狂的事情:-)您是否有可能将外部重定向的规则集与我的第2部分中的“添加尾部斜杠状WP”部分结合起来。编辑到一个规则?请在您的帖子的另一个代码部分添加一个带有尾随斜杠的解决方案(与%{QUERY_STRING},means/path?var=to/path/?var=)好吗?这将是最伟大的事情@艾迪弗雷迪:请检查我上面编辑的答案。现在,这些重定向将始终添加带或不带查询字符串的尾部斜杠
/