can someone tell me how to write rewrite rule: I have many links that look like:
http://www.mavrica.com/index.php?eID=tx_cms_showpic&file=uploads%252Fpics%252Fmozic_05.jpg&width=800m&height=600m&bodyTag=%253Cbody%2520bgcolor%253D%2522black%2522%253E&wrap=%253Ca%2520href%253D%2522javascript%253Aclose()%253B%2522%253E%2520%257C%2520%253C%252Fa%253E&md5=025892981ebd7f312b96276beb3ee194
I would like to redirect all of them to http://www.mavrica.com/fotogalerije/
All the links have in common first part (up to tx_cms_showpic).
I tried the following htaccess rules:
RewriteRule /index.php?eID=tx_cms_showpic$ http://mavrica.com/fotogalerije/ [R=301]
and with
RedirectMatch 301 ^/index.php?eID=tx_cms_showpic(.*) http://www.mavrica.com/fotogalerije/
but none of them work.
What have I missed out?
Thanks for help!
You need to use %{QUERY_STRING} to capture and/or match the query string part of the URL:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?eID=tx_cms_showpic [NC]
RewriteRule ^ http://mavrica.com/fotogalerije/? [R=301,L]
Related
I have many URLs like this:
https://www.url.com/user/shop/location/scoobydoo
They all begin the same, but the username at the end is different. I am trying to redirect 301 them all to:
https://www.url.com/profile-scoobydoo
This works if I use:
RewriteCond %{HTTP_HOST} www\.url\.com$
RewriteCond %{REQUEST_URI} ^\/user\/shop\/location\/scoobydoo$
RewriteRule .* https://www.url.com/profile-scoobydoo [R=301,L]
The problem is, I have several thousand users and while generating them all would work, it would completely flood the .htaccess file. Surely there must be an easier way to do this by username?
But how? Any help is greatly appreciated.
Try :
RewriteEngine on
RewriteRule ^user/shop/location/(.+)$ https://example.com/profile-$1 [L,R=301]
You can also use RedirectMatch directive
for your url redirection
RedirectMatch 301 ^/user/shop/location/(.+)$ https://example.com/profile-$1
I already have a couple of rules set up such as
RewriteCond %{HTTP_HOST} ^www.pipcanadaltd\.com$ [NC]
RewriteRule .?$ http://ca.pipglobal.com%{REQUEST_URI} [R=301,L]
And I also have rewrites for a few PHP pages such as:
RewriteRule ^products/eye-protection-experts/$ prod-expert-eyewear.php [NC,L]
For some reason, when I went to create a simpler 301 redirect, it is not working. Here is what I have:
RewriteRule ^products/construction-channel-experts/$ ^products/construction-safety-solutions/ [R=301]
I'm really confused on why this doesn't work.
You can use this rule for 301 redirect:
RewriteRule ^products/construction-channel-experts/?$ /products/construction-safety-solutions/ [R=301,L,NC]
Note that ^ is used for matching start position in regex and it can only be used in pattern which is on left hand side.
You should keep redirect rules before internal rewrite rules.
i would like to make a 301 redirect and from an old website using the exact exact url with no extra parameters.
example:
/en-direct.php?page=7
to go to:
http://www.example.org/news/
and page:
/en-direct.php?page=8
to go to:
http://www.example.org/awesome-but-totally-different-page/
i used:
redirectMatch 301 ^/en-direct.php$ http://www.example.org/different-page/
redirectMatch 301 ^/en-direct.php?page=7$ http://www.example.org/news/
redirectMatch 301 ^/en-direct.php?page=8$ http://www.example.org/awesome-but-totally-different-page/
however: i get http://www.example.org/different-page/ every time with all the parameters from the redirect page (example - http://www.example.org/different-page?page=7 )
any help will be much appreciated.
In order to match against the query string, you need to use mod_rewrite:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^page=7($|&)
RewriteRule ^en-direct\.php$ http://www.example.org/news/ [L,R=301]
RewriteCond %{QUERY_STRING} ^page=8($|&)
RewriteRule ^en-direct\.php$ http://www.example.org/awesome-but-totally-different-page/ [L,R=301]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^en-direct\.php$ http://www.example.org/different-page/ [L,R=301]
I have link like this:
www.site.com/page.php?p=1
Need to rewrite it to friendly URLs in htaccess
RewriteRule ^home$ page.php?p=1
It works but now I have two active links with the same content.
Tried to add 301 redirect from old link to new but stuck in loop. Any ideas how to fix that?
Try matching against the actual request so that your rules won't loop:
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /page\.php\?p=1(&|\ |^)([^\ ]*)
RewriteRule ^page\.php$ /home?%3 [L,R=301]
# then your internal rewrite
RewriteRule ^home$ page.php?p=1
Remove the redirect on the page and handle it in the htaccess.
RewriteRule ^page\.php\?p=1$ /home [L,R=301]
This will redirect to /home and stop the redirect loop you have now.
another quick & dirty way to prevent looping in these situations i've found is to add a querystring and then check for its existence in the redirect.
RewriteCond %{QUERY_STRING} ^p=1
RewriteCond %{QUERY_STRING} !foo=bar
RewriteRule ^page\.php$ /home [NC,R=301,L]
RewriteRule ^home$ page.php?p=1&foo=bar [NC,L]
found on this site: http://answers.oreilly.com/topic/542-how-to-properly-redirect-for-maximum-seo/
Redirect 301 /page.php?p=1 www.yourwebsite.com/home?p=1 RewriteRule
^home?p=1$ /page.php?p=1
I have read about htaccess redirect and rewrite on stackoverflow and on other sites and learned how to redirect simple pages and directories, but there are about 30 links remaining that I haven't been able to redirect. The reason appears to be because they contain "?" in the link's URL. I've tried the solutions posted but I haven't been able to make enough sense of them to succeed.
These work:
Redirect /Corpfleet.php htp://www.marketyourcar.cm/wraps.php
Redirect /drivers.php htp://www.marketyourcar.cm/drivers.php
Redirect /galleries.php htp://www.marketyourcar.cm/galleries.php
These do NOT work:
Redirect /ad.php?View=FAQ htp://www.marketyourcar.cm/advertiser-faqs.php
Redirect /ad.php?View=gallery htp://www.marketyourcar.cm/galleries.php
Redirect /ad.php?View=Materials htp://www.marketyourcar.cm/products-services.php
Yes, I know that the URL above is htp and .cm - I had to break it in order to make this post with my low reputation level.
If anyone can help with this I'd appreciate it.
Thanks
If you want to redirect from like:
site.com/index.php?blabla=1&id=32
to
site.com/contact.html
then use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} blabla=1&id=32
RewriteRule ^(.*)$ http://www.site.com/contact.html? [R=301,L]
</IfModule>
Redirect can't handle that. RewriteRule can. This should work.
RewriteEngine on
RewriteRule ^/ad\.php\?View\=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php [R=301,L]
RewriteRule ^/ad\.php\?View\=gallery$ http://www.marketyourcar.cm/galleries.php [R=301,L]
RewriteRule ^/ad\.php\?View\=Materials$ http://www.marketyourcar.cm/products-services.php [R=301,L]
Or try this:
RewriteEngine on
RewriteRule ^/ad.php?View=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php [R=301,L]
RewriteRule ^/ad.php?View=gallery$ http://www.marketyourcar.cm/galleries.php [R=301,L]
RewriteRule ^/ad.php?View=Materials$ http://www.marketyourcar.cm/products-services.php [R=301,L]
This might work:
Example:
RewriteEngine On
RewriteRule ^/ad.php?View=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php? [R=301,L]
Add a trailing ? to the substitution URL to remove the incoming query.