简体   繁体   中英

mod_rewrite backwards for old dynamic urls

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 ie 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM