Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.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 合并几个Mod重写规则_.htaccess_Mod Rewrite - Fatal编程技术网

.htaccess 合并几个Mod重写规则

.htaccess 合并几个Mod重写规则,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,这更像是这个问题的后续问题: 我有以下规则: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> 这些结果是否正确(正确的顺

这更像是这个问题的后续问题:

我有以下规则:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
这些结果是否正确(正确的顺序和规则)


重新启动发动机
重写cond%{HTTP_HOST}^$
重写cond%{HTTP_HOST}^www\。[北卡罗来纳州]
在上重写cond%{HTTPS}s^|
重写规则^http%1://www.%{http_HOST}%{REQUEST_URI}[R=301,L]
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
到目前为止,一切都按预期进行,但我的所有测试都是在临时URL中进行的,而不是在实际域中进行的


谢谢

这些规则应该满足您的要求,但我会稍微调整一下。由于您所做的一切都有效,因此这些都只是基于我的偏好提出的建议。:)


重新启动发动机
重写基/
重写cond%{HTTP_HOST}^$
重写cond%{HTTP_HOST}^www\。[北卡罗来纳州]
在上重写cond%{HTTPS}s^|
重写规则^http%1://www.%{http_HOST}%{REQUEST_URI}[R=301,L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php/$1[L]
我发现当所有不是规则的重写选项都放在第一位时,阅读起来会更容易。我还喜欢添加空行,以便更容易看到一组规则的结束和下一组规则的开始

此规则是不必要的:
RewriteRule^index\.php$-[L]
,因为下一条规则只会影响对未映射到真实文件的URI的请求。因为index.php存在于文件系统中,所以它不会触发下一条规则

对于index.php规则,添加/$1会使请求在$\u服务器['PATH\u INFO']中可用,这可能会有所帮助,具体取决于代码的编写方式。这绝对不是必需的,但WordPress或CodeIgniter等应用程序建议这种方法是很常见的,所以我认为值得一提

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php/$1 [L]
</IfModule>