简体   繁体   中英

.htaccess in subfolder

The main site runs WordPress with .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

I'm going to create an CodeIgniter app in subdirectory site.com/online/ If simply add CI .hta file in subfolder it wouldn't work. CI .htaccess:

RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|img|styles|js)
RewriteRule ^(.*)$ /index.php?/$1 [L]

Is it possible to combine two .htaccess files or to do something with .htaccess in CI subfolder? Thank you.

UPD. Thank you for answers, I've tried all variants, and eventually moved project to subdomain.

First thing, your .htaccess should be like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} !^GET\s/+online/ [NC]
RewriteRule . /index.php [L]
</IfModule>

#Then add this for CI handling in the same .htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !index\.php [NC]
RewriteRule ^online/(.*)$ online/index.php?/$1 [L,NC]

Then you can remove (or rename) .htaccess in the online subfolder.

Try this for the codeigniter .htaccess:

RewriteEngine on
RewriteBase /online
RewriteCond $1 !^(index\.php|robots\.txt|img|styles|js)
RewriteRule ^(.*)$ /index.php?/$1 [L]

Otherwise all requests to that subfolder would be redirected down to wordpress.

Are you setting AllowOverride ? According to the docs you need to allow FileInfo overrides for mod_rewrite.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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