我使用Laravel,所以我重写规则以重定向到index.php,我还有规则重定向到www和https。
我想要URI" / blog "不要重定向到index.php,但我需要它像:
实际上它重定向到:
example.com/blog
因为这条规则RewriteCond $1 !^(blog)
将其排除在重写规则之外
这是我的规则:
<IfModule mod_rewrite.c>
RewriteBase /
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond $1 !^(blog) #I need this to get www and https but not further rules
# To https
RewriteCond %{REQUEST_SCHEME} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# To www if is not a subdomain
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^(.*)\.(.*)\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
答案 0 :(得分:1)
如果您希望从blog/
重写中跳过index.php
,请将最后一条规则更改为:
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^blog(/.*)?$ index.php [L,NC]