rewrite google custom search string

2019-04-14 16:53发布

问题:

My previous custom google search appeared this how:

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

I change my Google CSE script. Now im usign jsapi. My new search generates:

(second link) http:/raskim.lt/controller/function/music?q=this%is%example

How to rewrite url that if someone visit first link, would be redirected to second link?

Now my .htaccess looks:

<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>

回答1:

Add this to your .htaccess in your web root / directory

RewriteEngine on
RewriteBase /

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