简体   繁体   中英

CodeIgniter URL rewriting

I am trying to rewrite the URL of a CodeIgniter application, though it doesn't seem to work. I have the following things set;

$route['pages/(:num)/(:any)'] = "pages/view/$1/$2";
$config['index_page'] = '';

Then I have the following .htaccess;

RewriteEngine on
RewriteBase /

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

It just says the page is not found (an Apache error, not CodeIgniter). It works when I browse to the original link (http://domain.tld/index.php/pages/view/1/welcome) but not when browsing to the 'desired' link (http://domain.tld/pages/1/welcome).

What am I doing wrong?

Could it be that you are missing a ? in your RewriteRule?

# Substitute " >>?<< " with "?". It's there to point you to the change.
RewriteRule ^pages/(.*)/(.*)$ /index.php >>?<< /pages/view/$1/$2 [L]

Try:

$route["pages/(.*)/(.*)"] = "pages/view/$1/$2";
//and your htacess, remove your current rule and
RewriteRule ^(.*)$ index.php/$1 [L]

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