Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.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
Apache .htaccess将只重定向而不重写_Apache_Codeigniter 3_.htaccess - Fatal编程技术网

Apache .htaccess将只重定向而不重写

Apache .htaccess将只重定向而不重写,apache,codeigniter-3,.htaccess,Apache,Codeigniter 3,.htaccess,我想将example.com/foo重写为example.com/index.php?bar(php codeigniter) 所有文件都在同一个域上 作为起点和验证设置,以下代码成功重定向: RewriteCond %{HTTPS} on RewriteRule ^foo/$ https://example.com/index.php?bar [L,QSA,NC] 但我想重写,而不是重定向。我一直不知道该怎么做。我尝试了以下重写规则: #These don't work RewriteRul

我想将example.com/foo重写为example.com/index.php?bar(php codeigniter)

所有文件都在同一个域上

作为起点和验证设置,以下代码成功重定向:

RewriteCond %{HTTPS} on
RewriteRule ^foo/$ https://example.com/index.php?bar [L,QSA,NC]
但我想重写,而不是重定向。我一直不知道该怎么做。我尝试了以下重写规则:

#These don't work
RewriteRule ^foo1/$ index.php?/bar [L,QSA,NC]
RewriteRule ^foo2/$ /index.php?/bar [L,QSA,NC]
RewriteRule ^foo3/$ index.php?/bar [L,QSA,NC,P]
RewriteRule ^foo4/$ /index.php?/bar [L,QSA,NC,P]
RewriteRule ^foo5/$ index.php?/bar [L,QSA,NC,PT]
RewriteRule ^foo6/$ /index.php?/bar [L,QSA,NC,PT]
RewriteRule ^foo7/$ https://example.com/index.php?/bar [L,QSA,NC,PT]
完整访问权限在这里:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


RewriteCond %{HTTPS} on
RewriteRule ^foo/$ https://example.com/index.php?/bar [L,QSA,NC]    #works but redirects
RewriteRule ^foo1/$ index.php?/bar [L,QSA,NC]
RewriteRule ^foo2/$ /index.php?/bar [L,QSA,NC]
RewriteRule ^foo3/$ index.php?/bar [L,QSA,NC,P]
RewriteRule ^foo4/$ /index.php?/bar [L,QSA,NC,P]
RewriteRule ^foo5/$ index.php?/bar [L,QSA,NC,PT]
RewriteRule ^foo6/$ /index.php?/bar [L,QSA,NC,PT]
RewriteRule ^foo7/$ https://example.com/index.php?/bar [L,QSA,NC,PT]
</IfModule>

选项+FollowSymLinks
重新启动发动机
重写基/
重写条件%{HTTPS}关闭
重写规则(.*)https://%{HTTP_HOST}%{REQUEST_URI}[R=301,L]
在上重写cond%{HTTPS}
重写规则^foo/$https://example.com/index.php?/bar [L,QSA,NC]#工作但重定向
重写规则^foo1/$index.php?/bar[L,QSA,NC]
重写规则^foo2/$/index.php?/bar[L,QSA,NC]
重写规则^foo3/$index.php?/bar[L,QSA,NC,P]
重写规则^foo4/$/index.php?/bar[L,QSA,NC,P]
重写规则^foo5/$index.php?/bar[L,QSA,NC,PT]
重写规则^foo6/$/index.php?/bar[L,QSA,NC,PT]
重写规则^foo7/$https://example.com/index.php?/bar [L、QSA、NC、PT]

您的想法太复杂了。保持简单:

RewriteEngine On

RewriteCond %{HTTPS} !on
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,QSA]

RewriteRule ^/?foo/?$ /bar [END]
从http到http的重定向应该首先完成,独立于内部重写。你需要把它分开

此规则同样适用于http服务器主机配置或动态配置文件(“.htaccess”文件)中。显然,重写模块需要在http服务器中加载,并在http主机中启用。在使用动态配置文件的情况下,您需要注意在主机配置中启用该文件的解释,并且该文件位于主机的
DOCUMENT\u ROOT
文件夹中

如果您使用上述规则收到一个内部服务器错误(http状态500),那么很可能您操作的是非常旧版本的apache http服务器。在这种情况下,您将在http服务器错误日志文件中看到不支持的
[END]
标志的明确提示。您可以尝试升级或使用较旧的
[L]
标志,在这种情况下可能也会使用相同的标志,不过这取决于您的设置


还有一个一般性的注释:您应该总是更喜欢将这些规则放在http服务器主机配置中,而不是使用动态配置文件(“.htaccess”)。这些动态配置文件增加了复杂性,通常是导致意外行为的原因,难以调试,而且它们确实降低了http服务器的速度。只有在您无法访问真正的http服务器主机配置(读:真正廉价的服务提供商)或坚持编写自己的规则的应用程序(这显然是一个安全噩梦)的情况下,才提供它们作为最后一个选项

/bar
URI是否在不同的域上?/bar在同一个域上RewriteRule^/?foo/?$/bar/[QSA,L]#works RewriteRule^/?foo2/?$/bar/[QSA,L]#works RewriteRule^/?foo3/?$/index.php/[QSA,L]#没有正确地重写rule^/?foo4/?$/index.php?/offers[QSA,L]#没有正确重写我的问题与Coder有关。此解决方案解决了现在发布在此处的新问题: