【问题标题】:How to redirect links to other link without changing the address bar如何在不更改地址栏的情况下将链接重定向到其他链接
【发布时间】:2012-12-09 07:11:32
【问题描述】:

我想将http://example.com/username 之类的链接重定向到http://example.com/ index.php?id=username 这样我就使用了这些 .htaccess 规则:

RewriteEngine On    
RewriteBase /    
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com    
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([a-z0-9-]+)/? http://example.com?id=$1 [R=301,NC,L]

但是有一个问题。 URL被重定向,但是浏览器的地址栏也被改变了。

如何在不更改地址栏的情况下将链接重定向到其他链接?

【问题讨论】:

  • 我不得不从最后一行删除 R=301http://myDomain.com

标签: .htaccess


【解决方案1】:

这是一个工作示例:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.co.uk$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.co.uk$
RewriteCond %{REQUEST_URI} !example/
RewriteRule (.*) /foldername/$1 [L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-25
    • 1970-01-01
    • 2011-06-10
    • 2010-11-02
    • 1970-01-01
    • 2015-01-25
    相关资源
    最近更新 更多