【问题标题】:Redirect String .htaccess重定向字符串 .htaccess
【发布时间】:2013-07-14 16:01:39
【问题描述】:

我是 .htaccess 的新手,想从 .htaccess 重定向 URL

喜欢:

http://test.example.com/abc/xyz/456adf646asdf

http://test.example.com/abc/xyz?id=456adf646asdf

http://test.example.com/abc/xyz/?456adf646asdf

请帮忙。

我试过了:

重写规则 ^(.+)/abc/xyz/$ /abc/xyz?id=$1

但对我不起作用..

【问题讨论】:

  • 你没试过吗?
  • 我试过了,但对我不起作用..RewriteRule ^(.+)/ride/linkedin/$ /ride/linkedin?id=$1
  • 编辑您的问题并使用您的示例进行更新
  • 完成。请检查问题。
  • 试试RewriteRule ^/ride/linkedin/(.+)$ /ride/likedin?id=$1

标签: php .htaccess url redirect


【解决方案1】:

您还应该有一个 RewriteCond 来匹配传入的 URL 模式。试试这个来匹配你的明确大小写。

 RewriteCond %{REQUEST_URI} ^/abc/xyz/(.\*)
 RewriteRule (.\*) /abc/xyz?id=%1 [L]

当然有很多选择。你也可以试试

  RewriteCond %{REQUEST_URI} ^/(.\*)/(.\*)/(.\*)  
  RewriteRule (.\*) /%1/%2?id=%3 [L]

在您的示例中,%1 将匹配“abc”,%2 将匹配“xyz”,而 %3 456adf646asdf。

mod_rewrite 安装了吗?

【讨论】:

  • 这工作但不显示 id...staging.rdfs.in/ride/linkedin/?id=
  • 请发回您使用的重写规则。
  • 感谢您格式化代码。昨天刚加入,这是我的下一课。
  • 感谢 Tanstaafi 先生和 AKAM 先生的回复,但在两次更改后显示此错误“在此服务器上找不到请求的 URL /abc/xyz/232323asf。”
  • 试试这个:RewriteCond %{REQUEST_URI} ^/abc/xyz/(.*)/ RewriteRule (.*) /abc/xyz?id=%1 [L] with url: example.com /ride/linkedin/12122/
【解决方案2】:

那是行不通的。试试这个:

RewriteRule ^/abc/xyz/(.+)$ /abc/xyz?id=$1

【讨论】:

    猜你喜欢
    • 2017-02-09
    • 2015-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-13
    • 2010-11-06
    相关资源
    最近更新 更多