【问题标题】:Redirect one URL to another on same domain with htaccess使用 htaccess 将一个 URL 重定向到同一域上的另一个 URL
【发布时间】:2017-03-16 12:59:55
【问题描述】:

我目前正在建立一个新网站。旧网站的网址与新网站不同。现在我想重定向,使用 htaccess。

在上线之前,我想在本地测试我的规则。

旧网站使用这种格式的网址:

www.domain.de/?content=whatevercontent

新网站使用这种格式的网址:

www.domain.de/index.php?content=differentcontentname

哪些被重写(在 htaccess 文件中,使用多个 RewriteRules)为这种格式:

www.domain.de/nicecontentname

我尝试过这样的重定向:

Redirect http://domainfolder/?content=whatevercontent http://10.3.10.69/domainfolder/nicecontentname

这不起作用。

上线后应该是这样的:

Redirect http://www.domain.de/?content=whatevercontent http://www.domain.de/index.php?content=differentcontentname

..然后被重写为漂亮的url。

我的重定向规则不适用,我尝试了所有我能想到的组合,有或没有 http,有或没有包含文件夹,使用已经重写的 url 或实际的,等等。 关于这个问题有什么想法吗?

【问题讨论】:

    标签: .htaccess url redirect url-rewriting


    【解决方案1】:

    您不能使用重定向指令来操作查询字符串。这是一个适用于 QueryStrings 的 mod-rewrite 示例:

    RewriteEngine on
    
    RewriteCond %{THE_REQUEST} \s/\?content=this
    RewriteRule ^$ /index.php?content=that [L,R]
    

    这会将 /?content=this 临时重定向到 /index.php?content=that

    要使重定向永久化(浏览器可缓存),请将 R 更改为 R=301。

    【讨论】:

    • 谢谢斯塔基恩。你能举一个没有正则表达式的例子吗,只有一个重写,然后我可以改变几个网址?这会是: RewriteRule /index.php?content=differentcontentname$ /?content=whatevercontent
    猜你喜欢
    • 2017-05-18
    • 2013-08-04
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-09
    • 2015-10-28
    • 1970-01-01
    相关资源
    最近更新 更多