简体   繁体   中英

Explain htaccess code used to run CodeIgniter from subfolder

I'm running CodeIgniter from a subdirectory, where mydomain.com opens my default_controller (currently the welcome screen) and this snippet seems to work for to that end, when placed in my /root/.htaccess, but even with references it's still magic to me.

Options +FollowSymLinks
RewriteEngine On
RewriteBase /app/main/build/www

RewriteRule ^$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)

RewriteRule ^(.*)$ index.php?/$1 [L]

Can someone explain this htaccess snippet at a low-level line by line? and have I missed anything vital? This is in my /root folder and it takes are of getting rid of index.php out of the url so I've placed no .htacces in my /root/app/build/www/subfolder

I wrote some comments in the code:

# Tell the server to follow symbolic links
Options +FollowSymLinks

# Enable mod-rewrite
RewriteEngine On

# Strip /app/main/build/www from the string to be tested by regex
RewriteBase /app/main/build/www

# If the url empty, redirect to index.php (^ is start of line, $ is end of line)
RewriteRule ^$ index.php [L]

# If the url is not an existing directory
RewriteCond %{REQUEST_FILENAME} !-d
# And if the url is not an existing fie
RewriteCond %{REQUEST_FILENAME} !-f
# And if the file does not start with index.php or the other two...
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
# Then rewrite the url to index.php?file, and make this the last rule
# Note that (.*) captures every character of the file name to Group 1, and that
# $1 is a reference to that capture (used once in the cond, once in the rule)
RewriteRule ^(.*)$ index.php?/$1 [L]

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