简体   繁体   English

向后mod_rewrite以获取旧动态网址

[英]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". 我可以在Apache 2.2上正常运行mod-rewrite,但是问题是它不能“向后”运行。

I have these rules that makes SEO friendly urls work: 我有使SEO友好的url工作的这些规则:

 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 但是“旧”网址仍然有效,即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. 如果要直接或从旧链接加载这些URL,我想重写这些URL,以便只使用一个url方案。

Assuming you have a page to report errors, 404 in particular, you can add this rule at the end and you should be fine: 假设您有一个页面来报告错误,尤其是404,则可以在末尾添加此规则,您应该可以:

RewriteRule ^.*$ __404_PAGE_HERE__

This will redirect all requests that didn't match your previous rules to your 404 page. 这会将所有与您之前的规则不匹配的请求重定向到404页面。

Best wishes. 最好的祝愿。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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