在godaddy
托管public_html
上作为网络根目录给出。我正在尝试CodeIgniter
在其上安装,因此webroot
出于安全原因,我希望整个框架都在外部。为此,请在public_html
我.htaccess
使用以下代码创建的目录中:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ [NC]
RewriteCond %{REQUEST_URI} !^/sub_webroot/
RewriteRule ^(.*)$ ./sub_webroot/index.php?$1 [L]
目录/文件结构如下所示:
public_html
.htaccess
CodeIgniter (whole framework files except index.php)
sub_webroot
index.php (CI index.php)
assets
sample.png
该框架已成功加载,并且index.php
也已删除。我面临的问题是我无法打开sample.png
通孔example.com/assets/sample.png
,很明显由于线路的缘故,它正在发生RewriteRule ^(.*)$ ./sub_webroot/index.php?$1 [L]
。我无法下定决心,如何访问assets
目录并使框架在目前正常运行的情况下仍能成功运行。有什么想法可以改变.htaccess
以满足我的需求吗?
这就是我们解决此问题的方法:如果从资产文件夹请求,则添加条件以忽略重写。您可以根据需要添加/删除选项以将其忽略-实际上,您只需要使用资产选项即可。
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document
RewriteCond $1 !^(index\.php|assets|css|png|jpg|gif|robots\.txt|favicon\.ico)
将其放在您的RewriteRule之前。
对于麻烦的主机,有一个非常全面的Codeigniter .htaccess,网址为:http : //www.chrishjorth.com/blog/one-com-codeigniter-htaccess-rewrite-rules/,并对此进行了评论:
# @author: Chris Hjorth, www.chrishjorth.com
# Make index.php the directory index page
DirectoryIndex index.php
#Protect the .htaccess files
<Files .htaccess>
order allow,deny
deny from all
</Files>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subfolder/
# START CodeIgniter ------------------------------------------------------------------------------------------------------------
# based on http://www.danielwmoore.com/extras/index.php?topic=7691.0 and http://ellislab.com/forums/viewthread/132758/
# Redirect default controller to "/".
# This is to prevent duplicated content. (/welcome/index => /)
RewriteRule ^(welcome(/index)?)/?$ /subfolder/ [L,R=301]
# Remove /index/ segment on the URL, again to prevent duplicate content.
RewriteRule ^(.*)/index/? $1 [L,R=301]
# Remove trailing slashes, also to remove duplicate content
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Remove multiple slashes in between, just to remove the possibility of fabricating crazy links.
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
# Ignore certain files and folders in this rewrite
RewriteCond $1 !^(index\.php|assets|frameworks|uploads|robots\.txt|favicon\.ico)
# [NC] = no case - case insensitive
# [L] = Last rule, last rewrite for this set of conditions
# [QSA] = Query String Append, should be used to prevent all redirects from going to your default controller, which happens on
# some server configurations.
RewriteRule ^(.*)$ /subfolder/index.php?$1 [NC,L,QSA]
# END CodeIgniter --------------------------------------------------------------------------------------------------------------
</IfModule>
# If Mod_rewrite is NOT installed go to index.php
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句