0

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?

4
  • I think you need to have htaccess to remove index.php from url and it should work Commented Dec 21, 2011 at 10:01
  • Not quite, it's not just removing the 'index.php' but also the name of the method; view.
    – Roel
    Commented Dec 21, 2011 at 10:04
  • Have you checked the apache logs to find out what apache is rewriting this to? Additionally you may want the non greedy version of the match for $1 ie ^pages/(.*?)/(.*)$
    – Bob Vale
    Commented Dec 21, 2011 at 10:14
  • I don't want to sound too dumb, but apparently my server did not support htaccess yet, I changed the apache vhost and now it's working with a little bit of tweaking.
    – Roel
    Commented Dec 21, 2011 at 10:21

2 Answers 2

1

Try:

$route["pages/(.*)/(.*)"] = "pages/view/$1/$2";
//and your htacess, remove your current rule and
RewriteRule ^(.*)$ index.php/$1 [L]
1
  • Figured it out using this. Thanks.
    – Roel
    Commented Dec 21, 2011 at 10:21
1

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]
1
  • Not that, Codeigniter uses the slash format, plus op states that manually using the rewritten version works
    – Bob Vale
    Commented Dec 21, 2011 at 10:14

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.