I have some SEO to do on my site.
I'd like that the page 'red-bags' point to the search page 'search.php?keyword=red bags'
In addittion I'd like that the old search page makes a 301 redir to the new red-bags.
RewriteBase /
RewriteRule ^red-bags /search\.php/keyword=red\sbags [NC,L]
RewriteCond %{QUERY_STRING} keyword=red\sbags
RewriteRule ^search.php http://www.mysite.com/red-bags [R=301,L]
The second rules not work. Please help.
Try changing the second rule to this:
RewriteCond %{QUERY_STRING} keyword=red%20bags
RewriteRule ^search.php http://www.mysite.com/red-bags? [R=301,L]
In the first line the space is changed to the urlencoded %20
The question mark at the end of red-bags strips off the query string, otherwise it would have automatically been appended to the new url.
Related
I need to set up redirect 301 in .htaccess file but old link contain & signs. So, it is not works
My old link: /index.php?option=com_content&view=article&id=62&Itemid=75
so, I tried this:
RewriteCond %{QUERY_STRING} ^option=com_content&(.*)$
RewriteRule .+ / [R=301,L]
Can you help me with that?
Also I have this old link: /index.php?parametr1=services¶metr2=Recovery_Services¶metr3=Orthopedic_in_home_care
You need to use a question mark at the end of the Rewrite destination
RewriteCond %{QUERY_STRING} ^option=com_content&(.*)$
RewriteRule .+ /? [R=301,L]
? is important here to discard the old query string from the new url otherwise you will end up at /?oldquerystring
A image gallery moves to a new place.
Old:
album_showpage.php?pic_id=1
New:
/image/gallery/image_page.php?image_id=1
The new file
image_page.php
make a 301 redirect to something like this:
/category-1/image-1.html
I need a hidden redirect from old to new.
I tried:
RewriteRule ^album_showpage.php?pic_id=([0-9]+) /image/gallery/image_page.php?image_id=$1 [L]
But album_showpage.php gives me always a 404.
Thank you
Use that:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^pic_id=(\d+)$ [NC]
RewriteRule ^album_showpage\.php$ /image/gallery/image_page.php?image_id=%1 [L]
I try to change over htaccess from
http://www.mydomain.com/pictures/generated/product/1/280_280_75/nopic.jpg
to
http://www.mydomain.com/pictures/generated/product/1/280_280_75/nopic1.jpg
Here is my rules
RewriteCond %{HTTP_HOST} ^mydomain\.com
RewriteRule nopic\.jpg$ nopic1\.jpg
It works in some way;) The whole URL will be changed just to "nopic1.jpg".
The question is: How can I change only the last part of URL?
This should work:
RewriteRule ^(.*)nopic\.jpg$ $1nopic1\.jpg
I'm new with 301 redirects through .htacces.
I can get simple redirects as
redirect 301 /test.html http://www.domain.com/test2.html
to work but I have some urls like this
redirect 301 /test.asp?Group=100 http://www.domain.com/test3.html
and for some reason these don't work.
Thanks.
Here is set of rules for URLs you have provided:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} =group=113 [NC]
RewriteRule ^group\.asp$ http://domain.dk/til-born.htm? [NC,R=301,L]
RewriteCond %{QUERY_STRING} =product=1136 [NC]
RewriteRule ^product\.asp$ http://www.domain.dk/til-born/bukser.html? [NC,R=301,L]
As you can see query string is matched separately to the page name. So .. for each of such redirects you need 2 lines: RewriteCond & RewriteRule.
The rule above will do EXACT match, which means /group.asp?group=113¶m=value will not be redirected because query string is group=113¶m=value which is more than just group=113.
To have such redirect working (when there are some optional parameters in query string) you have to modify it: RewriteCond %{QUERY_STRING} (^|&)group=113(&|$) [NC] -- this will match group=133 anywhere in query string (group=113 and group=11366 are still different, so no problems here).
This needs to be placed in .htaccess in website root folder. If placed elsewhere some tweaking may be required.
The Redirect directive (as far as I know) matches only on the path, not querystring. Instead, use RewriteRule. The QSA instructs the rewrite engine to append the querystring onto the new redirected URL.
RewriteEngine On
RewriteRule ^test\.asp http://www.domain.com/test3.html [L,R=301,QSA]
I need to redirect
/search?keywords=somesearchterm
to
/search/somesearchterm
This seems incredibly basic but I've been pounding my head against it for an hour.
Thanks for taking the time to look at this.
You want to implement what is called a "301 Redirect" with mod_rewrite.
RewriteEngine ON
RewriteRule ^/search\?keywords=somesearchterm$ /search/somesearchterm
adding regular expressions:
RewriteEngine ON
RewriteRule ^/search\?keywords=(.+) /search/$1 [R=301,L]
R=301 means provide a 301 Header redirect so the user's URL changes in the browser, and L means don't process any more rewrite rules if this one matches.
If you want to do the reverse -- in other words, if someone goes to mysite.com/search/asearchterm and you want the URL to stay the same, but "behind the scenes" you want it to load a certain server script, do this:
RewriteEngine ON
RewriteRule ^/search/(.+) /search.php\?keywords=$1 [L]
You can not match aginst Query string in RewriteRule directive. Use %{THE_REQUEST} or %{QUERY_STRING} server variables to match the Query string :
The following rule works fine for this redirection
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/search\?kewords=([^&\s]+) [NC]
RewriteRule ^ /search/%1? [NE,NC,R,L]
RewriteRule ^search/([^/]+)/?$ /search?keyword=$1 [QSA,NC,L]