0

I have mod-rewrite working ok on an apache 2.2, but the problem is that it doesn't work "backwards".

I have these rules that makes SEO friendly urls work:

 RewriteRule ^sjg/([^/]+)/([0-9]+)/?$           /showimage.php?model=$1&image=$2 [L]
 RewriteRule ^sjg/([^/]+)/page/([0-9]+)/?$      /model.php?model=$1&page=$2      [L]
 RewriteRule ^sjg/([^/]+)/?$                    /model.php?model=$1              [L]

But the "old" urls still work i.e. website.com/showimage.php?model=abc&image=123

I would like to rewrite those urls if they are loaded directly or from old links in order to have only one url-scheme working.

1 Answer 1

1

Assuming you have a page to report errors, 404 in particular, you can add this rule at the end and you should be fine:

RewriteRule ^.*$ __404_PAGE_HERE__

This will redirect all requests that didn't match your previous rules to your 404 page.

Best wishes.

3
  • but my goal is that if someone loads the old urls, they do get the page but from the "new" url.
    – Jesper
    Commented May 24, 2013 at 1:54
  • Oh pardon me. Well what comes at the top of my mind is to check the $_SERVER['REQUEST_URI'] and after a few validations you should be able to determine the redirect link I suppose. @Jesper
    – php_nub_qq
    Commented May 24, 2013 at 1:56
  • OK Thanks, I guess I can code my way out of it, I was thinking of a .htaccess / mod_rewrite solution, but I have just done it with PHP instead (as you suggest) :)
    – Jesper
    Commented May 24, 2013 at 2:18

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.