简体   繁体   English

.htaccess 将所有内容重定向到“/public”,除了子文件夹中的“/blog”

[英].htaccess redirect everything to “/public” except for “/blog” in subfolder

i have an .htaccess file to redirect all users to my index.php in /public:我有一个 .htaccess 文件,可以将所有用户重定向到 /public 中的 index.php:

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^(.*)$ public/index.php?$1 [L,QSA]

I want to add a blog to my site as a wordpress subfolder in /blog.我想在我的网站上添加一个博客作为 /blog 中的 wordpress 子文件夹。

I tried adding:我尝试添加:

RewriteCond %{REQUEST_URI} !/blog

as a condition, but my site keeps redirecting everything to /public.作为一个条件,但我的网站不断将所有内容重定向到 /public。 Any ideas?有任何想法吗?

Cheers.干杯。

Sounds pretty straight forward:听起来很直接:

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]

RewriteCond %{REQUEST_URI} !^/blog/?
RewriteRule ^(.*)$ public/index.php?$1 [L,QSA]

I, personally, would always prefer that notation:我个人总是更喜欢这种表示法:

RewriteEngine On
RewriteBase /

RewriteRule ^/?public/(.*)$ /$1 [L,NE,R=302]

RewriteCond %{REQUEST_URI} !^/blog/?
RewriteRule ^/?(.*)$ /public/index.php?$1 [END,QSA]

If that does not work for you, then you will need to start debugging: start monitoring your http server's error log file and also the networking tab inside your browsers console.如果这对您不起作用,那么您将需要开始调试:开始监视 http 服务器的错误日志文件以及浏览器控制台中的网络选项卡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM