简体   繁体   中英

How to rewrite URL in codeigniter with htaccess?

How can I rewrite a URL from

http://website.com/index.php/content/index/3

to

http://website.com/content/3

in the .htaccess file?

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. 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>

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