简体   繁体   中英

How to rewrite URL in CodeIgniter?

I am learning CodeIgniter.I want to rewrite URLs so that localhost/tutorial/index.php/cart/product becomes localhost/tutorial/cart/product

I tried to edit my .htaccess file inside the application folder with the following code:

RewriteEngine on
ReWriteCond $1 !^(index\.php|images|swf|uploads|js|css|robots\.txt)
ReWriteRule ^(.*)$/tutorial/index.php/$1[L]

but it didn't work. My CI file name is tutorial and CI version is 2.0.

I tried and worked for me.

<IfModule mod_rewrite.c>

        # Make sure directory listing is disabled
        Options +FollowSymLinks -Indexes
        RewriteEngine on
        RedirectMatch 403 ^/(system\/pyrocms\/cache|system\/codeigniter|\.git|\.hg).*$

        # Send request via index.php (again, not if its a real file or folder)
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d

        RewriteRule ^(.*)$ index.php/$1 [L]


    </IfModule>

I have tried that .htaccess file and it seems to work (note the extra spaces in the last line)

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /tutorial/index.php/$1 [L]

Also check if mod_rewrite is enabled in your system (in Ubuntu and similar systems you can use a2enmod rewrite : it should say that it is already enabled).

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