Search code examples
wordpress.htaccess

.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:

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.

I tried adding:

RewriteCond %{REQUEST_URI} !/blog

as a condition, but my site keeps redirecting everything to /public. Any ideas?

Cheers.


Solution

  • 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.