Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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 "domain.com/fooBar.html" I want to be able to serve it from "domain.com/foo/bar" and:

  • keep old website link versions accessible from outside: "domain.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: "domain.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 "domain.com/foo/bar":

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

Is there a better way?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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