仅当我有/ blog / URI时,如何重定向到子目录

时间:2010-12-06 20:51:24

标签: .htaccess

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 /被重定向,其余所有内容都应该如此? 感谢

我想要的是:

  1. 不是域/博客的网址正常运行并指向“web / index.php”

  2. 只有“域/博客”指向“web / blog / index.php”

1 个答案:

答案 0 :(得分:0)

是的,这可能非常简化,以满足您的需求。除非webblog都使用良好的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>