Ste*_*ven 9 php apache .htaccess mod-rewrite codeigniter
我正在运行CodeIgniter平台,该平台使用.htaccess接受类似的URL
http://www.mysite.com/controller/function/argument
Run Code Online (Sandbox Code Playgroud)
我目前使用一些.htaccess重写,即(简化):
RewriteEngine On
RewriteCond %{REQUEST_URI} !^(/index\.php|/images|/assets)
RewriteRule ^(.*)$ /index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)
我想添加一个重写规则,将所有非www请求重定向到www.我还希望域名后面的URI字符串在重定向中保持不变.例如,如果用户发出请求http://mysite.com/controller/function/argument,我希望.htaccess文件在浏览器中重写请求http://www.mysite.com/controller/function/argument,然后处理请求.
ekh*_*led 14
我遇到了类似的问题,这个.htaccess对我有用
RewriteEngine On
#This bit rewrites your host name to include www
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC,L]
#This bit does the codeigniter magic
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)
ros*_*oft 10
它应该是这样的:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Run Code Online (Sandbox Code Playgroud)