简体   繁体   English

301 重定向 htaccess

[英]301 Redirect htaccess

im having a problem with my htaccess我的 htaccess 有问题

I have the following我有以下

Redirect 301 /inspection-test.html http://www.newsit.co.uk/inspection-test.aspx

My current site runs on php and the new one runs on .net我当前的站点在 php 上运行,新站点在 .net 上运行

The redirect works but its showing as重定向有效,但显示为

http://www.newsit.co.ukinspection-test.html

You can try to use RedirectMatch Apache HTTPD Docs instead:您可以尝试改用RedirectMatch Apache HTTPD Docs

RedirectMatch 301 ^/inspection-test\.html$ ttp://www.newsit.co.uk/inspection-test.aspx

Redirect Apache HTTPD Docs will add the original URL-part to the end of the redirect URL which produces the unexpected output in your case on your server. Redirect Apache HTTPD 文档会将原始 URL 部分添加到重定向 URL 的末尾,这会在您的服务器上产生意外的 output。

With RedirectMatch you can better control the behavior.使用RedirectMatch ,您可以更好地控制行为。

Strange.奇怪的。

The url-part appended at the end of the path should only happen i your Redirect first argument is a directory, not for a file.附加在路径末尾的 url 部分应该只发生在您的 Redirect 第一个参数是目录而不是文件的情况下。

Now while you're testing the rewrites you shouldn't use 301 codes, as your browser will store the 1st result (so your first test) and will never ask the server for the fixed mapping (if you fix it).现在,当您测试重写时,您不应该使用301代码,因为您的浏览器将存储第一个结果(所以您的第一个测试)并且永远不会向服务器询问固定映射(如果您修复它)。 So it can be as well that you need to switch off your browser before redoing the redirect test.因此,您也可能需要在重做重定向测试之前关闭浏览器。 So maybe your rule is OK but your browser is not testing it.所以也许你的规则是好的,但你的浏览器没有测试它。

While you're testing you should use 302 redirect codes.在测试时,您应该使用302重定向代码。

Theres a lot of pages and all the url's differ页面很多,所有的网址都不同

You should study RewriteMap .你应该学习RewriteMap If you can list quite easily the old url and map each one to a new url url then a txt: map will dop the job, first with 302 codes, and when you're ok with it use a 301 code with a hash map file instead of a text one. If you can list quite easily the old url and map each one to a new url url then a txt: map will dop the job, first with 302 codes, and when you're ok with it use a 301 code with a hash map file而不是文字。

RewriteMap oldtonew txt:/path/to/my/hashmap/oldtonew.txt [NC]
# detect new url from map file
RewriteCond  ${oldtonew:%{REQUEST_URI}|NotFound}  !NotFound
RedirectRule .?  ${oldtonew:%{REQUEST_URI}}  [NC,R=301]
#no mapping
RewriteCond  ${oldtonew:%{REQUEST_URI}|NotFound}  NotFound
RedirectRule .?  http://www.example.com/notfound.html  [NC,R=301]

In oldtonew.txt write things like that在 oldtonew.txt 写这样的东西

/inspection-test.html http://www.newsit.co.uk/inspection-test.aspx
/inspection-foo.html http://www.newsit.co.uk/inspection-bar.aspx

Else if you can express the old-to-new mapping with some keywords in the old url, the DirectoryMatch could maybe do the trick, or some mod-rewrite with the good extractions.否则,如果您可以使用旧的 url 中的一些关键字来表达旧到新的映射,那么DirectoryMatch可能会起到作用,或者通过良好的提取进行一些 mod-rewrite。 But the faster solution is the rewriteMap with an hash file (dbm).但更快的解决方案是使用 hash 文件 (dbm) 的 rewriteMap。

Finally If you can express your old-to-new url mapping only with a with a program (a database?) you'll have to use the prg: keyword (quite hard) in rewriteMap.最后,如果您只能使用程序(数据库?)来表达您从旧到新的 url 映射,您将不得不在 rewriteMap 中使用prg:关键字(非常困难)。

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

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