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

发布于 2024-10-06 11:28:37 字数 981 浏览 0 评论 0原文

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. 仅“domain/blog”指向“web/blog/index.php”

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>

Hi there, I am not that good with a htaccess yet, just need a quick help.
the file above redirects everything to "blog" subdirectory.
How can I make sure that only url/blog/ gets redirected and all the rest does as it should?
thanks

What I want is:

  1. url that is not domain/blog to act as normal and point to "web/index.php"

  2. Only the "domain/blog" to point as "web/blog/index.php"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诺曦 2024-10-13 11:28:37

是的,这可能非常适合您的需求。除非webblog都使用良好的前端控制器模型,只需要让服务器重定向到它们。

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>

Right, this is probably very simplified for your needs. Unless both the web and blog use good Front Controller models that just need to have the server redirect to them.

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文