I have a pretty old website (running on Apache) that serves around 50 static HTML pages. And so I want to change it and add PHP Router to help me serve content in a RESTful way.

Now I have tried several things, but I don't know how good they are.

Say I have old page example.com/fooBar.html I want to be able to serve it from example.com/foo/bar and:

  • keep old website link versions accessible from outside: example.com/fooBar.html
  • make all requests go through index.php where I can use PHP Router, serve proper content for requests, keep old meta tags content intact (RESTful URIs should have same exact data)
  • NOT have ugly links like this: example.com/index.php?page=foo/bar
  • keep old version of a website's Google rating somewhat same
  • keep 301 Redirects to a minimum (2 is max I guess?)
  • change all website's inner links to new RESTful versions

So far I see that I can reference old pages to index like so:

RewriteCond %{REQUEST_FILENAME} !index.php
RewriteRule .* index.php?url=$0 [QSA,L]

This sends old pages to index.php and I can route Old Resources to New Ones like so: Changing location with router: $response->header("Location", "/foo/bar");

So the goal is for the location to look like example.com/foo/bar:

"example.com/fooBar.html" => index.php Router => "example.com/foo/bar"
"example.com/foo/bar"     => index.php Router => "example.com/foo/bar"

Is there a better way?

1 Answer 1


You have the right idea. The only thing that I would suggest would be to change your rewrite condition somewhat. I would use:

RewriteCond %{REQUEST_FILENAME} !-f  # not a real file
RewriteCond %{REQUEST_FILENAME} !-d  # not a directory
RewriteCond %{REQUEST_FILENAME} !-l  # not a symbolic link

This would prevent the rewrite rule from triggering on index.php (just like your rule does.) It would also allow you to serve other files (such as a robots.txt file, image files, or a pdf file) in the normal static manner.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.