使用.htacces更改特定页面的URL

时间:2015-11-07 05:52:22

标签: .htaccess mod-rewrite url-rewriting url-redirection

我需要更改此网址的一部分

page.com/OLD?q=text+phrase

有了这个

page.com/NEW?q=text+phrase

请注意:此网址是搜索结果,在这种情况下,完整网址是从以下部分构成的:

  • page/ - 域名
  • /OLD - 此部分(路线)需要更改
  • ?q= - 是查询字符串
  • text+phrase - 这是某些用户在搜索框中写入的文字,因此点击“输入”,此文字将添加到网址末尾,用户将被重定向到“搜索结果”网页“

我需要这个重定向仅用于外部网址(由谷歌索引)因为我有130.000网址索引(mysite / old?q = ...)

这是我的实际代码(此OLD - to - NEW - 未在此代码中添加,因为我的所有意图都是为了获得正确的代码,而且还有faill)

    <IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    RewriteCond %{THE_REQUEST} /index\.php [NC]
    RewriteRule ^(.*?)index\.php[^/] /$1? [L,R=301,NC,NE]

    RewriteCond %{THE_REQUEST} /index\.php [NC]
    RewriteRule ^(.*?)index\.php(?:/(.*))?$ /$1$2? [L,R=301,NC,NE]

    RewriteRule ^/?filme-online/(.*)$ /online-filme/$1 [L,R=301]
    RewriteRule ^/?filme-online(.*)$ /online-filme$1 [L,R=301]
    RewriteRule ^/?seriale-online/(.*)$ /online-seriale/$1 [L,R=301]
    RewriteRule ^/?seriale-online(.*)$ /online-seriale$1 [L,R=301]

    # Redirect Trailing Slashes...
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

1 个答案:

答案 0 :(得分:0)

如果您要在htaccess文件中添加规则,则以下内容应该有效:

RewriteCond %{QUERY_STRING} ^q= [NC]
RewriteRule ^busqueda\b /busquedaS [R=301,L,QSA]