Need some help trying to redirect a domain:
https://www.example.com/blog/page/10/?page_id=%2Ffeed%2Fatom%2F to /blog/
I think the best way is to just redirect anything after /page
The code below is what I'm thinking but I know is not correct:
RewriteEngine on
RewriteCond %{THE_REQUEST} /blog/page/[0-255]* [NC]
RewriteRule ^ /blog/? [NC,R=301,L]
Any advice?
Need some help trying to redirect a domain:
If you are trying to redirect the domain use something like
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [OR]
RewriteRule ^(.*)$ "http://www\.exampe2\.com\/blog/" [R=301,L]
If you want to append the request to the URL use $1
If you're rewriting the path to /blog/ and want to keep the query string use the [QSA] flag ie.
RewriteRule /blog/(.*) /blog/ [R=301,QSA,L]
this will make sure you keep your query string.
Related
How can I add the Google translate parameter #googtrans(en|de) or other language, so the translation happens automatically?
Basically, when the user goes to https://example.com/page/?lang=de they are redirected to https://example.com/page/?lang=en#googtrans(en|de)
I use this .htaccess rule, but it's not working:
RewriteCond %{QUERY_STRING} ^lang=([a-z]{2})$
RewriteRule ^/?lang=en#googtrans(en|[a-z]{2}) [R=301,L]
EDIT: Adding edited Rules here.
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/page/?\?lang=([a-z]{2})\s [NC]
RewriteRule ^ page/?lang=%1#googtrans(%1) [R=301,L,NE]
With your shown samples(this is considering that you are hitting URL like: https://example.com/page/?lang=de in browser), please try following .htaccess Rules file. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{QUERY_STRING} ^lang=([a-z]{2})$ [NC]
RewriteRule ^page/?$ page/?lang=%1#googtrans(%1) [R=301,L,NE]
I am trying to redirect to a new domain, but it isn't retaining the complete url on the redirect, it only goes to the homepage. Here is the line in my htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*\.old-domain\.com
RewriteRule ^(.*)$ http://www.new-domain.com/$1 [R=permanent,L]
For example, if I go to www.old-domain.com/contact-us/request-a-demo/, it should go to www.new-domain.com/contact-us/request-a-demo/
Instead, anything I type after the first "/" is redirecting to the homepage for www.new-domain.com
What am I missing, please help
Maybe you could try this:
RewriteEngine On
RewriteCond %{SERVER_NAME} ^(.+\.)?old-domain\.com
RewriteRule ^/?(.*)$ http://www.new-domain.com/$1 [R=permanent,L]
I have the following to my .htaccess
RewriteEngine on
RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]
When I call www.mydomain.com/page/myvalue I get the correct result. In order to to that though I'll need to change all links to my website correct?
Is there a way to accomplish the opposite i.e. when I call index.php?page=$1 to redirect me to www.mydomain.com/page/myvalue ?
Add this rule to your .htaccess:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ page/%1? [R=301,L]
I want to create a condition that if page has parameter in URL like ?print=1 - redirect this page to itself without any querystring.
Example:
I want this page:
http://sos-med.com/en/specific_page.html?print=1&ok=1
tp redirect (301) to the same URL with no Query string:
http://sos-med.com/en/specific_page.html
My code is:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^*print=*$ [NC]
RewriteRule ^(.*)$ %{REQUEST_URI}?
I have no test server, so can you tell me if my code is ok?
The code above is for every page on website. And before implementing that rule I would like to try the redirect for one specific page (see my example).
How to modify the code to work with "specific_page.html" only?
I want only .htaccess solution, not PHP code.
You're close, your %{QUERY_STRING} regex isn't right, and you're missing the 301 redirect flag:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^print=.*$ [NC]
RewriteRule ^(.*)$ %{REQUEST_URI}? [L,R=301]
Try that.
Thanks, and If I want to redirect single specific page: sos-med.com/en/aaa.html?print=1&ok=1 to sos-med.com/en/aaa.html ? –
Then you'd change what the rule matches against:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^print=.*$ [NC]
RewriteRule ^en/aaa.html$ %{REQUEST_URI}? [L,R=301]
Try this one instead :
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*&)?print= [NC]
RewriteRule ^(.*)$ /$1? [L,R=301]
I want htp://www.seostuff.org.ua/?s=seo to be redirected to htp://seo.seostuff.org.ua
Instead of seo can be any other search pattern
Buy this way I managed to make htp://seo.seostuff.org.ua redirecting to htp://www.seostuff.org.ua/?s=seo
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.seostuff\.org\.ua
RewriteCond %{HTTP_HOST} ^(.*)\.seostuff\.org\.ua [NC]
RewriteRule .* http://www.seostuff\.org\.ua/?s=%1 [L]
But I do not want URL change it should stay the same, ex htp://seo.seostuff.org.ua
I want revert requests to be processed as well (means htp://www.seostuff.org.ua/?s=seo should 301 redirect to htp://seo.seostuff.org.ua)
Also I do not need any slowness of processing such URL requests. Want to create optimized Rules. Any help please?
I would really appreciate this.
You cannot rewrite to a full HTTP URL without redirect to it.
So try this:
RewriteEngine on
# rewrite abc.seostuff.org.ua to abc.seostuff.org.ua/?s=abc
RewriteCond %{HTTP_HOST} !^www.seostuff.org.ua
RewriteCond %{HTTP_HOST} ^(.*).seostuff.org.ua
RewriteRule .* ?s=%1 [L]
# redirect seostuff.org.ua/?s=abc to abc.seostuff.org.ua
RewriteCond %{QUERY_STRING} ^s=([a-zA-Z0-9\-_]+)$
RewriteRule .* http://%1.seostuff.org.ua/ [L,R=301]