Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
# uncomment the following line, if you are having trouble
# getting no_script_name to work
#RewriteBase /
# we skip all files with .something
#RewriteCond %{REQUEST_URI} \..+$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
# we redirect to blog if requested
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule .* /blog/index.php [L]
</IfModule>
您好,我对htaccess不太好,只需要快速帮助。 上面的文件将所有内容重定向到“blog”子目录。 我怎样才能确保只有url / blog /被重定向,其余所有内容都应该如此? 感谢
我想要的是:
不是域/博客的网址正常运行并指向“web / index.php”
只有“域/博客”指向“web / blog / index.php”
答案 0 :(得分:0)
是的,这可能非常简化,以满足您的需求。除非web
和blog
都使用良好的Front Controller模型,只需将服务器重定向到它们。
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# skip all files that exist
RewriteCond %{REQUEST_FILENAME} !-f
# match anything that starts with /blog/ to the blog index
RewriteRule ^/blog/ /web/blog/index.php [L,QSA]
# everything else to /web/index.php
RewriteRule ^(.*)$ /web/index.php [L,QSA]
</IfModule>