301 Redirect Dynamic URL with .htaccess - regex

I have dynamic URL that I want to redirect (301) with .htaccess.
Old URL:
mysite.com/index.php?route=product/search&keyword=searchphrase
New URL:
mysite.com/index.php?route=product/search&search=searchphrase
I need that the redirect will change the URL from search&keyword to search&search, but will keep the searchphrase.
How to do this?
Thanks!

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(index\.php\?route=product/search)&keyword=([^\s&]+) [NC]
RewriteRule ^ /%1&search=%2 [R=301,L,NE]

Related

.htaccess Redirect 301 with ? (without variables)

There are some urls with ?.
/shop/index.php?route=affiliate/register
/shop/?route=affiliate/register
It is needed for these urls to be redirected to:
/another-page/
(asume all urls begin with the home directory. example: www.homepage.com/shop?route=affiliate/register )
I have tried both simple apache Redirect 301 and rewrite.
You may use this rule as your top rule in site root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} /shop/(?:index\.php)?\?route=[^\s&]+ [NC]
RewriteRule ^ /another-page/? [R=301,L,NE]

htaccess rewrite URL and remove GET parameters

I am new to URL rewrite, regex and .htaccess
Here is an issue I am facing:
I have this url with GET parameter:
www.mysite.in/alpha-beta/abc.php?id=APPLE%strike=200.00
I want to display it like:
www.mysite.in/alpha/beta/APPLE/200.00
This is the code in .htaccess:
RewriteRule ^alpha/beta/(.*)/([0-9]+(\.[0-9]+))$ alpha-beta/abc.php?id=$1&strike=$2 [NC,L]
But I only get a blank page when I go to URL: www.mysite.in/alpha/beta/APPLE/200.00
When I change the htaccess rule to:
RewriteRule ^alpha/beta/(.*)/([0-9]+(\.[0-9]+))$ http://www.mysite.in/alpha-beta/abc.php?id=$1&strike=$2 [NC,L]
It redirects to correct page but the URL is displayed as http://www.mysite.in/alpha-beta/abc.php?id=APPLE&strike=200.00
What seems to be the problem?
Use these rules in root .htaccess:
RewriteEngine On
RewriteRule ^OI_TOOL/IV/(.*)/([0-9]+(?:\.[0-9]+))/?$ OI_ANALYSIS_TOOL/iv_chart.php?symbol=$1&str‌​ike=$2 [NC,L,QSA]
# fix path for getIV.php by redirecting it to /OI_ANALYSIS_TOOL/
RewriteRule ^OI_TOOL/.+?/(getIV\.php)$ /OI_ANALYSIS_TOOL/$1 [L,NC,R=301]

htaccess gives 404 i qualified the page is there

I have a site created specific for mobiles. I added the code below into my htaccess for a redirect but it does not seem to work.
Can anyone enlighten me please
#custom redirects
RewriteEngine on
Redirect 301 /cartypes.php?cartype=12 http://m.cartypecompany.com/redcars.php
#end custom redirects
Redirect directive is not used with mod_rewrite's RewriteEngine On and you need a RewriteCond to match query string. Use this rule:
RewriteEngine on
RewriteCond %{HTTP_HOST} =m.cartypecompany.com
RewriteRule ^redcars\.php$ /cartypes.php?cartype=12 [L,NC,QSA]

Redirect from page without parameters to page with parameters in htaccess

I need to redirect from page like this www.site.ru/machines/ to page www.site.ru/machines/?set_filter=y&PRICE_MIN=4500 in the mod_rewrite section of .htaccess.
You can use this rule in root .htaccess:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(machines/)$ /$1?set_filter=y&PRICE_MIN=4500 [L,NC,R]

Magento htaccess Rewrite and Redirect

On a Magento based ecommerce site I am trying to remove index.php from URLs as well as 301 redirect non-www to www.
Default URL: www.example.com/index.php/super-cool-product.html
Desired Product URL: www.example.com/super-cool-product.html
Also 301 redirecting non-www to www:
example.com/super-cool-product.html
to:
www.example.com/super-cool-product.html
As well as:
www.example.com/index.html
to:
www.example.com
This is what I currently have:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301]
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.rejuvahealth.com/$1 [R=301,NC,L]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.rejuvahealth.com/$1 [R=301,NC,L]
To 301 redirect index.html:
Options +FollowSymLinks
RewriteEngine on
redirect 301 /index.html http://www.example.co.uk/
If you configure your Base URLs correctly, Magento should automatically redirect to the www. version.
For index.php rewrites, go to Configuration > Web > Use Web Server Rewrites and change to 'Yes'.
Now open your htaccess and change this line:
#RewriteBase /magento/
to this:
RewriteBase /
Assuming that your Magento folder is on the root. Be careful when using web rewrites though and ensure you back up before making any changes.