简体   繁体   English

htaccess将动态网址重定向到静态网址

[英]htaccess redirect dynamic url to static url

I've some url rewrites something like that: 我有一些网址重写这样的东西:

RewriteRule ^futbol-video/([^/]*)-([^-]*)\.html$ /html/video.php?text=$1&id=$2 [L]

RewriteRule ^futbol-takimi/([^/]*)-([^-]*)\.html$ /html/takim.php?text=$1&id=$2 [L]

I'm trying to redirect dynamic queries to static pages. 我正在尝试将动态查询重定向到静态页面。 I've tried something below but get everytime internal server error. 我在下面尝试了一些方法,但是每次都出现内部服务器错误。 How shoul I write the rule form 301 redirects? 我应该如何编写规则表单301重定向?

First I've tried: 首先,我尝试过:

RewriteRule ^futbol-video/([^/]*)-([^-]*)\.html$ /html/video.php?text=$1&id=$2 [R=301,L]

RewriteRule ^futbol-takimi/([^/]*)-([^-]*)\.html$ /html/takim.php?text=$1&id=$2 [R=301,L]

But get internal server error. 但是出现内部服务器错误。

I believe you are handling query strings incorrectly. 我相信您处理的查询字符串不正确。

See the following blog posts for some examples that utilize RewriteCond for handling query strings. 有关使用RewriteCond处理查询字符串的一些示例,请参见以下博客文章。

  1. http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects
  2. http://www.simonecarletti.com/blog/2009/01/apache-rewriterule-and-query-string/ http://www.simonecarletti.com/blog/2009/01/apache-rewriterule-and-query-string/

Example from the blog: 来自博客的示例:

#Keep original query (default behavior)
RewriteRule ^page\.php$ /target.php [L]
# from http://example.com/page.php?foo=bar
# to   http://example.com/target.php?foo=bar

#Discard original query
RewriteRule ^page\.php$ /target.php? [L]
# from http://example.com/page.php?foo=bar
# to   http://example.com/target.php

#Replace original query
RewriteRule ^page\.php$ /target.php?bar=baz [L]
# from http://example.com/page.php?foo=bar
# to   http://example.com/target.php?bar=baz

#Append new query to original query
RewriteRule ^page\.php$ /target.php?bar=baz [QSA,L]
# from http://example.com/page.php?foo=bar
# to   http://example.com/target.php?foo=bar&bar=baz

EDIT Additionally, if you are trying to redirect FROM a url with query strings to a static page, the url with the query string must come first in the rewrite rule (or be placed in a rewrite condition), not second like you have it. 编辑此外,如果您尝试从具有查询字符串的URL重定向到静态页面,则具有查询字符串的url必须在重写规则中排在第一位(或置于重写条件下),而不要像您拥有它那样排在第二位。

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

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