【问题标题】:rewrite google custom search string重写谷歌自定义搜索字符串
【发布时间】:2013-08-15 00:17:56
【问题描述】:

我之前的自定义谷歌搜索是这样出现的:

(第一个链接)http://raskim.lt/controller/function/music?cx=014092587915392242087%3Agc6l6xlpkmq&cof=FORID%3A11&q=this%is%example&sa=Search

我更改了我的 Google CSE 脚本。现在我使用 jsapi。我的新搜索生成:

(第二个链接)http://raskim.lt/controller/function/music?q=this%is%example

如何重写url,如果有人访问第一个链接,将被重定向到第二个链接?

现在我的 .htaccess 看起来:

<IfModule mod_rewrite.c>

Options +FollowSymLinks -Indexes
RewriteEngine on


#AllowOverride All
#RewriteBase /
    RewriteCond %{HTTP_HOST} !^www\.raskim\.lt$
    RewriteRule ^(.*)$ http://www.raskim.lt/$1 [L,R=301]
# Restrict your site to only one domain
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_php5.c>
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

【问题讨论】:

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


    【解决方案1】:

    将此添加到您的网络根/ 目录中的.htaccess

    RewriteEngine on
    RewriteBase /
    
    RewriteCond %{QUERY_STRING} &q=([^&]+) [NC]
    RewriteRule ^(.*/music)$ $1?q=%1 [R=301,NC,L]
    

    【讨论】:

    • 将此代码添加到我的 .htaccess 后,我在我的 url raskim.lt/home/yeylt/domains/raskim.lt/public_html/home/yeylt/… 中得到了这个,我认为这是因为我的其他人 RewriteRules
    • 用您当前的 htaccess 代码更新您的 qn。还有其他规则吗?
    • 是的。这些-&lt;IfModule mod_rewrite.c&gt; Options +FollowSymLinks -Indexes RewriteEngine on #AllowOverride All #RewriteBase / RewriteCond %{HTTP_HOST} !^www\.raskim\.lt$ RewriteRule ^(.*)$ http://www.raskim.lt/$1 [L,R=301] # Restrict your site to only one domain #RewriteCond %{HTTP_HOST} !^www\. #RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d &lt;IfModule mod_php5.c&gt; RewriteRule ^(.*)$ index.php?/$1 [L] &lt;/IfModule&gt; &lt;IfModule !mod_php5.c&gt; RewriteRule ^(.*)$ index.php?/$1 [L] &lt;/IfModule&gt; &lt;/IfModule&gt;
    • 你的RewriteBase# 注释掉了。您可以启用然后尝试吗?如果它不起作用,也可以尝试/$1 开启和关闭重写基础。
    • 根据 Ravi Thapliyal 我启用了这一行 #RewriteBase / 现在我的问题解决了。重写工作
    猜你喜欢
    • 1970-01-01
    • 2015-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-13
    • 2013-01-21
    相关资源
    最近更新 更多