My website is running on InfinityFree hosting and it ads ?i=1 suffixes (like www.mysite.com/?i=1, or /?i=2, or /?i=3) to every URL to protect websites against malicious bots, as they say.
But of course, I don't like these suffixes and want to disable them (simply redirecting www.mysite.com/anypage/?i=1 to www.mysite.com/anypage/). Note that I don't want to disable all GET parameters, but only these i=1, i=2 and i=3.
I think it could be done using .htaccess. Can someone help me, please?
Well, I've solved the problem using a code from this question.
I've just added this code in my .htaccess, and now it redirects all the URLs with "i" to the URLs without it.
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)i=[^&]+(.*)$ [NC]
RewriteRule ^(.*)$ /$1?%1%2 [R=301,L]
You need to turn the RewriteEngine on first.
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)i=[^&]+(.*)$ [NC]
RewriteRule ^(.*)$ /$1?%1%2 [R=301,L]
Related
It is possible to redirect in .htaccess
this url
http://test.com/uploads/image.jpg?w=200
to this
http://test.com/public/uploads/image/200.jpg
?
I need this to cache system in my rest API.
I'm not sure that is possible rewrite get variable in this way.
Cheers
Check this rule, maybe it help.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^uploads/image.jpg
RewriteCond %{QUERY_STRING} w=(.*)
RewriteRule ^(.*)$ /public/uploads/image/%1.jpg? [R=301,L]
Good morning all,
When I do a search for the name of my site on google I end up with lots of links like mysite.com/?page=1
mysite.com/?page=2
Etc.
I would like to redirect 301 of these links which ends in mysite.com/?page=X
to monsite.com
Because I am afraid that Google will see it as duplicate content knowing that it displays all the home page of my site ...
I tried
RewriteCond %{QUERY_STRING} ^page=1(&|$) [NC]
RewriteRule ^(mysite)/?$ /$1? [R=301,L]
which doesn't work on my side.
Could you help me ?
Thanks in advance,
To redirect such requests this should be what you are looking for:
RewriteEngine on
RewriteCond %{QUERY_STRING} (?:^|&)page=\d+(?:&|$) [NC]
RewriteRule ^/?$ / [QSD,R=301,END]
Or a more general example which preserves given a path
RewriteEngine on
RewriteCond %{QUERY_STRING} (?:^|&)page=\d+(?:&|$) [NC]
RewriteRule ^ %{REQUEST_URI} [QSD,R=301,END]
Keep in mind however that even with such redirection you still have the issue that somewhere those references are generated. Google does not make them up. So to fix the actual issue and not just a symptom you will have to find the actual issue...
I have this dynamic link:
http://www.nortedigital.mx/article.php?id=36175&t=dobla_las_manos_el_snte__avala_reforma_educativa
and I need to convert in URL friendly like this:
http://www.nortedigital.mx/36174/se_enriquecio_elba_en_sexenios_del_pan.html
and i have this RewriteRule:
RewriteRule ^([^/]*)/([^/]*)\.html$ /article.php?id=$1&t=$2 [L]
but doesn't work. Please, anybody can help me?
You must capture the query string in a RewriteCond and use that in the RewriteRule
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=(\d+)&t=(.+)$
RewriteRule ^/?article\.php$ /%1/%2.html? [R,L]
This redirects the client to request i.e. /36174/se_enriquecio_elba_en_sexenios_del_pan.html. Now you must server the real page. For that, we add an additional rule, similar to the one you already have in your question
RewriteRule ^/?(.+?)/(.+?)\.html$ /article.php?id=$1&t=$2 [L]
But now, there's an endless redirect loop. We break this by using an environment variable. Here is the whole complete ruleset
RewriteEngine On
RewriteCond %{ENV:REDIRECT_SEO} ^$
RewriteCond %{QUERY_STRING} ^id=(\d+)&t=(.+)$
RewriteRule ^/?article\.php$ /%1/%2.html? [R,L]
RewriteRule ^/?(.+?)/(.+?)\.html$ /article.php?id=$1&t=$2 [L,E=SEO:1]
This rule does the redirect as above, as long as the environment variable is not set. And it serves the real page from article.php and sets the environment variable at the same time to prevent the loop.
You can use cookies for this purpose too. But that will break, if cookies are disabled in the client.
I have checked previous questions, I believe this is quite simple but I can't seem to work it out.
In my .htaccess file I currently have
RewriteCond %{HTTP_HOST} !^www\.bodycleansediet\.com [NC]
RewriteRule ^(.*)$ http://www.bodycleansediet.com/$1 [R=301,L]
However this is causing a problem as it also redirecting any sub-domains (specifically au.bodycleansediet.com and ca.bodycleansediet.com) to www.bodycleansediet.com
I want them NOT be to be redirected so they can be viewed on their sub-domains.
I know I need to add an exception/re-write rule but I am not sure how to construct it.
Any advice on how to construct this?
Should not something along the following lines work
RewriteCond %{HTTP_HOST} !^(www|ca|au)\.bodycleansediet\.com [NC]
RewriteRule ^(.*)$ http://www.bodycleansediet.com/$1 [R=301,L]
Since you are basically checking if not (www OR ca OR au) then do your redirect.
I found myself with this problem, which is driving me a little bit crazy. I use apache's mod_rewrite for pretty URLs and I need to use dynamic subdomains in the site. Everything is great and all the server has de wildcards. I use the next code on my .htacess:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mysite.com
RewriteCond %{HTTP_HOST} ([^.]+).mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/%1 [L]
The only problem is, even if I use the [L] flag the url of the site change to http://mysite.com/subdomain. What i want is the url to be like http://subdomain.mysite.com
The link mysite.com/subdomain is a dynamic url and is solved with another rule with the following code:
RewriteRule ^([A-Za-z]+)$ filter.php?type=subdomain&subdomain=$1
Any help would be appreciated
If you specify an external URL (which changing the subdomain does), a header redirect will take place. I don't think you can prevent that. But why not skip that step altogether, and use the second RewriteRule straight away?
I can't test this right now, but something like
RewriteCond %{HTTP_HOST} !^www.mysite.com
RewriteCond %{HTTP_HOST} ([^.]+).mysite.com [NC]
RewriteRule ^(.*)$ filter.php?type=subdomain&subdomain=$1
should work.