Forum Moderators: phranque
RewriteRule ^([^\-]+)-(.+)/$ question.php?fn=view&id=$1&seo_name=$2 [L]
You will be much happier in your mod_rewrite career if you never use the wild-card subpattern ".*" unless that is the only subpattern that will do what you want to do. It is a greedy, promiscuous, ambiguous, and --when used multiple times in one pattern-- awfully inefficient subpattern to use.
The "[^\-]+" subpattern shown here matches one or more characters that are not hyphens. So, it matches everything in the requested URL-path up to the first hyphen into $1 and then stops, leaving the rest to go into $2.
Jim
I was thinking of doing the actual redirections with header()'s in PHP to point the old pages to the new. I guess I must have been thinking about that when I made the title. Cheers ;)
With a rewrite, you continue to use the same old URLs out on the web even though the filenames on the server have changed.
When your script services the request, it needs to validate that $2 is the exact wording that does belong to the ID in $1. If it is not, then it needs to issue a 301 redirect to the exact correct URL. Failure to do so, allows people to link to your site like
example.com/4567-this-product-is-junk and for your server to serve that as if it were a valid address.