[英]Codeigniter remove index.php and prefix the URL with www
我想刪除Codeigniter
隨附的默認index.php
。
我已經可以使用此代碼將其刪除
RewriteRule ^(.*)$ index.php/$1 [L]
example.com/index.php/blog
現在可以通過訪問example.com/blog
后來我想在URL
加一個www
example.com/blog
應該使用這些重寫規則重定向到www.example.com/blog
。
RewriteCond %{HTTP_HOST} ^(?!www\.)(.+) [NC]
RewriteRule ^(.*) http://www.%1/$1 [R=301,NE,L]
將上面的代碼添加到我的.htaccess
文件的末尾后,它開始出現異常。
如果我在URL
輸入www.example.com/blog
可以正常工作,但是如果我輸入example.com/blog
則它將重定向到www.example.com/index.php/blog
我做錯了什么?
我希望example.com/blog
重定向到www.example.com/blog
注意:我正在使用Codeigniter
框架。
補充:這段代碼只是在我之前編寫的代碼的基礎上。 也許這是個問題,請幫助!!!
RewriteCond $1 !^{index\.php|[assests/images/themes/fonts/style/scripts/js/install]|robot\.txt|favicon\.ico}
嘗試這個:
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ example.com/$1 [L,R=301]
經過許多技巧之后,按照@Tpojka的帖子 ,我能夠想到這個
RewriteEngine On
RewriteBase /
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
# no www -> www
RewriteCond %{HTTP_HOST} ^(?!www\.)(.+) [NC]
RewriteRule ^(.*) http://www.%1/$1 [R=301,NE,L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
這家伙是我的問題
RewriteCond $1 !^{index\.php|[assests/images/themes/fonts/style/scripts/js/install]|robot\.txt|favicon\.ico}
我需要如何排除的文件夾,並像一些文件幫助robot.txt
就像我在出現故障的線路試圖文件。
這是我個人使用的完整的.htaccess文件:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.