I have problem with htaccess rewrite rule.
I have page for example:
www.oldpage.com/55,city.html?partner_id=7
www.oldpage.com/subpage/158,blog.html?partner_id=8
And I want to rewrite this page on:
www.newpage.com/55,city.html
www.newpage.com/subpage/158,blog.html
It is possible? Maybe I must redirect links with .html?partner_id on normal .html, after on newpage?
You can use the QSD flag (query string discard)
RewriteRule .* ww.newpage.com/$1 [NC,QSD]
I solved this problem by adding in .htaccess for newpage.com this code:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^partner_id=([0-9]*)$
RewriteRule ^(.*)$ /$1? [R,L]
Related
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.
Is it possible to redirect based on an url that would be as:
www.url.com/stuff.php
But not redirect if the url contained any characters after the php, as such:
www.url.com/stuff.php?variables=values&othervariable=othervalue&etc=more
I have no clue how to wriite this either.
Thanks in advance!
Edit: basically I need the redirect to happen to www.url2.com only if www.url.com ends with .php, but not if the .php is followed by variables.
try
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/site.com/?$ /site.com/cart.php [R=301,NC,L]
Try:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/?cart.php$ / [L,R=301]
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^stuff.php$ RELATIVE_OR_ABSOLUTE_URL_HERE [L]
I have an HTML file I want rewritten as a subfolder on the server.
http://www.example.com/kids-and-family/185-summer-camp.html
to be shortened to:
http://www.example.com/camp
Is there an rewrite condition where I can make this happen in .htaccess?
Can I say if (/camp) then display /kids-and-family/185-summer-camp.html?
I have been looking for this but have not found anything.
Try this rule:
RewriteEngine on
RewriteRule ^camp$ kids-and-family/185-summer-camp.html [L]
If you want an external redirect, add the R flag ([L,R]) with an additional redirect status like 301 for a permanent redirect ([L,R=301]).
in your .htaccess file, try this:
RewriteEngine on
RewriteCond %{REQUEST_URI} "/camp"
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{DOCUMENT_ROOT} /kids-and-family/185-summer-camp.html -s
RewriteRule ^$ /kids-and-family/185-summer-camp.html [L]
I am moving my site to new domain. Need to redirect pages
from
old-site.com/oldpage.php?id=X
to
new-site.com/newpage-X
(X is number)
Why this rule does not work?
RewriteEngine on
RewriteRule ^oldpage.php?id=(.*)$ http://new-site.com/newpage-$1 [R=301,L]
The RewriteRule does only operate on the URL path and not the URL query. You need to use the RewriteCond directive to test the URL query (%{QUERY_STRING}). So try this rule:
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)id=([^&]+)&?(.*)?$
RewriteRule ^oldpage\.php$ http://new.example.com/newpage-%3?%1%4 [L,R=301]
This rule will also preserve other parameters in the query.
I suspect that you will need to use QUERY_STRING
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^oldpage\.php$ http://new-site.com/newpage-%1 [R=301,L]
Hope this helps