使用htaccess

时间:2017-03-16 12:59:56

标签: .htaccess url redirect url-rewriting

我目前正在建立一个新网站。旧网站的网址与新网站不同。现在我想使用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

..然后被重写为好的网址。

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

1 个答案:

答案 0 :(得分:0)

您无法使用Redirect指令来操纵查询字符串。这是一个适用于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。

相关问题