[英]How to rewrite URL in codeigniter with htaccess?
How can I rewrite a URL from 我该如何从重写URL
http://website.com/index.php/content/index/3
to 至
http://website.com/content/3
in the .htaccess
file? 在
.htaccess
文件中?
I've tried this: 我已经试过了:
RewriteRule ^(.*)/(.*)$ index.php/$1/index/$2 [L]
But it didn't work. 但这没有用。
create .htaccess file in project root directory if other .htaccess file is not already created. 如果尚未创建其他.htaccess文件,请在项目根目录中创建.htaccess文件。 copy paste below codes into it .
将以下代码粘贴到其中。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /projectname
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
Use the following pattern : 使用以下模式:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/([\w-]+)$ index.php/$1/index/$2 [L]
</IfModule>
Try following Stuff: 尝试关注以下内容:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteBase /
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
#Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.