I have received (one time per month, not something to be worried but just strange) scraping visits that use a determined parameter: ?mdrv=. The problem is that these visits are from different IPs so blocking the IP is not a solution.
For example: example.com/?mdrv=, /category/the_category?mdrv= or /year/month/article.html?mdrv= (home page, category pages, post pages from home page or megamenu or simple pages in menu like /contact).
I´m trying to block this one but I cant get the correct code to block them (I get the one for home page but not for the others). How can I block them all?
Something like this should do it
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+[^?]*\?mdrv=
RewriteRule ^ - [F,L]
Related
We've got a couple redirects in place sending everything inside member.php (member profiles) to the forum home page:
RewriteRule ^member.php/(.*)$ https://www.domain.com/interact/ [L,R=301,NC]
RewriteRule ^member.php$ https://www.domain.com/interact/ [L,R=301,NC]
Unfortunately we need a specific member profile to be 410 Gone due to some serious issues with Google rankings (long story - spammy backlinks to it):
https://www.domain.com/interact/member.php/82683-Donaldpab
The first set of redirects is causing the Donaldpab profile page to forward you to the forum home page instead of show it as 410.
We had this redirect in place for it, but its being ignored:
Redirect 410 /interact/member.php/82683-Donaldpab
Tried this one also:
RewriteRule ^interact/member.php/82683-Donaldpab$ - [G,L]
I'm not a developer/tech person so I'm randomly guessing.
Is there a way to retain the first set of redirects, and just make this one user profile go 410 Gone?
Thank you.
The following redirect solved the problem. It allowed the overall "rules" for member profiles to remain in effect, while 410'ing the specific member profile:
RewriteRule ^member\.php/82683-Donaldpab$ - [G,NC]
Tested and confirmed with multiple profiles.
Is there the opportunity to get content on one url from another url? like this:
test.com/dir1 shows content from query test.com/getinfo/index.php?q=dir1
or
test.com/dir2 shows content from query test.com/getinfo.php?q=dir2
I need that because i must do 50 urls like test.com/dir1 ../dir50 which has the same template but with some different content based on query and one virtual url with query is better than 50 real directories.
I tried do but couldnt! Thanks in advance!
If it is all on the same host, then have a look at mod_rewrite, which can do amazing things. Just make sure you read the manual through, as there are a lot of details to take in.
RewriteEngine On
RewriteRule ^/dir1$ /getinfo/index.php?q=dir1 [L]
or more generically:
RewriteEngine On
RewriteRule ^/dir(.*)$ /getinfo/index.php?q=dir$1 [L]
I am sorry to ask this question, because the answer seemingly is so easy. However, after three hours of trial and error I am without a clue.
I have several pages on a website using parameters in the url. I would like to change that, to a more regular url. Example:
domain.com/pag.php?id=1-awesome-page should become domain.com/awesome-page
So far so good, but so far I have three problems.
1. The old page still is accessible, Google will index it as duplicated content. When I try to redirect it, I am getting infinite loop errors.
2. For whatever reason, sometimes SOME images (straight from the content) get stripped off on the newly named page. I tried playing with a base-url and renaming the images and urls, but nothing so far.
3. Also the redirect doesn't care if i'd enter id=1-awesome-page or id=2-worthless-page. It all redirects to the first one.
Among the things i've tried.
RewriteCond %{QUERY_STRING} id=1-awesome-page
RewriteRule ^pag\.php$ /awesome-page? [L,R=301]
RewriteRule ^awesome-page?$ pag\.php?id=1 [NC]
What you want to do cannot really be done with mod_rewrite, unless you want to make a rule for every page, which will probably slow your site down quite a lot. This is, because you can't summon the 1 in 1-awesome-page out of thin air, and your pag.php page doesn't seem to be able to load the page only based on it's seo name. If you need to use that number, you need to have that number somewhere in your url.
As for your questions:
The error you mention cannot be reproduced with the current iteration of your .htaccess. You likely had an infinite loop previously, and since you use R=301 to test, the browser will cache this redirect and only request the second resource afterwards when you request the first resource. You should test with [R,L] and only change to [R=301,L] when everything works as expected. Not doing so will cause weird behaviour, and behaviour you do not expect with your .htaccess.
When you have an url a and an url b, and want to redirect a to b, and want to internally rewrite b to a, you need to make sure that any given time not both rules can be matched. You can either use the %{THE_REQUEST} trick or use the END flag. Both are outlined in this answer.
If you have a problem with resources on a page not loading after making a fancy url, you likely used relative url's. This question outlines the possibilities on how to resolve this. You can either make the url's absolute or relative to the root of your site, or use <base href="/">.
The following would work for /pag.php?id=123-news-page and /news/123/news-page.
RewriteCond %{THE_REQUEST} pag\.php\?.*id=([^-]+)-([^&\s]+)
RewriteRule ^pag\.php$ /news/%1/%2? [L,R]
RewriteRule ^news/([^/]+)/([^/]+)/?$ pag.php?id=$1-$2 [L]
For the past 4 weeks (yes you read right, 4 weeks) I 've been trying to redirect my website to a new domain.
Here's what I want to do:
Redirect the ROOT of my website from ukmotorhomehirerental to leisurerentalsdirect.com
Without redirecting all the subfolders. ie. if I click on a link in google to one of our minor pages, I want to land on that page on the new domain without being redirected to the index page. It worth mentioning that I do want to also redirect the minor pages on a page to page basis.
I'm doing it like this (this works perfect)...
RedirectRule ^/pages/contentPage.asp\?QN=94 http://www.leisurerentalsdirect.com/pages/contentPage.asp?QN=94 [I,R=301]
However this This is were the problem lies...
RedirectRule ^/ http://www.leisurerentalsdirect.com [I,R=301]
I know the above implies to the browser that all traffic requesting ukmotorhomehirerental will be forwarded to leisurerentalsdirect
I think I need some sought of condition applying, but I just cannot understand how to do this, can anybody help?
You don't actually say what the problem is, but I think you want www.ukmotorhomehirerental.com to go www.leisurerentalsdirect.com and www.ukmotorhomehirerental.com/somepage to go to www.leisurerentalsdirect.com/somepage, right?
If so, you should only need a single redirect rule:
RewriteCond %{HTTP_HOST} ^www\.ukmotorhomehirerental\.com/? [NC]
RewriteRule ^(.*)$ http://www.leisurerentalsdirect.com/$1 [L,R=301]
This will simply redirect any page on ukmotorhomhirerental.com to the same page (or root, if none) on leisurerentalsdirect.com.
I need to know if there is a way to redirect long URLs to short URLs.
I have an RSS page that will list out a number of news items from my website. The URL format of each item (as per MySQL query) is something like http://example.com/news.php?id=2.
On my news.php (after being redirected to the news page upon clicking on any news title on the RSS page), there are parameters set to carry along the IDs which looks like http://example.com/news.php?news=2&view=1&topic=12.
For SEO purpose, I need to erase that dirty query string so that viewers will only see http://example.com/news.php?id=2 while on the server-side, it actually reads http://example.com/news.php?news=2&view=1&topic=12.
I had created an .htaccess file and it is placed inside the rss folder (where the rss.php file is located ) and tried several attempts but to no available.
Help me on this.
Here's what I would do:
RewriteEngine on
# id + view + topic
# http://www.domain.com/news/1/1/12 will load: /news.php?news=1&view=1&topic=12
RewriteRule ^news/([0-9]+)/([0-9]+)/([0-9]+)(/?)$ /news.php?news=$1&view=$2&topic=$3 [QSA,L,NC]
Please this .htaccess in the root folder.
Should the parameters be assigned to ($1,$2,$3...etc) instead?
RewriteRule ^news(/?)$ /news.php?news=$1&view=$2&topic=$3 [QSA,L,NC]