Redirecting a page to 410 when a more global redirect is taking precedence - .htaccess

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.

Related

Redirect 301 via htaccess with wildcard

I hope I am asking this questions correctly, if I am not, please feel free to correct me.
I am trying to redirect 301 via htaccess file for all user profiles within the same site so for example. The first section shows the actual URLs I want to redirect from and to where, but this is only focused on 1 user account.
Redirect 301 /otsn/members/admin/my-orders/ /otsn/members/admin/shop/
I am thinking can I use the percentage symbol to make this redirect universal to all users, maybe I'm wrong, Can I do the following?
Redirect 301 /otsn/members/%/my-orders/ /otsn/members/%/shop/
I created a better user profile shop tab that has more capabilities, so I want to get rid of the old one and in case anyone tries to enter the old version of that profile page tab by entering the url manually, I want them sent to the new version for their profile shop page but I want this to happen with every user profile in the system.
Is this the correct method? or is there a better more efficient way of doing this?
Thank you
You may use this rule as topmost rule in your .htaccess or Apache config:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/([\w-]+)/members/([\w-]+)/my-orders/?$ [NC]
RewriteRule ^ /%1/members/%2/shop [L,R=301]
%1 is back-reference for the first value we are capturing in RewriteCond i.e. first pattern in (...) and same way %2 will represent second captured value in (...).

htaccess redirect if the url does not contain a specific character

I'm moving the site to a subdomain and need certain tag strings to go to the subdomain and some to remain on the main site. Problem is both have a similar tag system.
I need this type of request
https://www.site.co.uk/tags/example-tag
to go here:
https://sub.site.co.uk/tags/example-tag
but this type of request
https://www.site.co.uk/tags/view?tags=14-some-varriable
to remain unchanged and parsed to content without redirecting.
What would be the most recommended and best solution?
I have written some code to work around other redirects but this one is causing me a headache.
Cheers
For your this mentioned example, below should work.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.+)/(.+)
RewriteRule ^ https://sub.site.co.uk/%1/%2 [R]

Renaming and redirecting pages fails in htaccess

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]

htaccess - Is this Correct?

Have looked through various articles both here and elsewhere but
could do with confirmation regards the way I have set up htaccess.
RewriteEngine On
RewriteCond %{HTTP_REFERER} orange [NC,OR]
RewriteRule .* blocked.php [L]
Can someone please confirm that given the code above that it will
block any domain, subdomain or page with the word orange in it?
It looks to be working but I need to ensure that I have covered all
bases and that I am blocking any link from or any image hotlinked from
my site where there is orange anywhere in the domain.
BTW I thought that if I have only one condition that I can leave out
the ,OR but when I removed it then it did not work in the test I was
doing??? Anyone know why this would not work without the ,OR ??
Many thanks in advance!
Can someone please confirm that given the code above that it will block any domain, subdomain or page with the word orange in it?
Yes, it will rewrite all requests to the /blocked.php script as long as "orange" is in the referer. The "Referer" header is what browsers typically include in a request letting the webserver know what page/site they were just at that linked to the resource that they're requesting. That means if there's a site called "orange.com" that has a page that links to one of your pages, and someone clicks on it, the referer will contain that orange.com page and the rules you have will block them.
You don't need the OR flag. Leaving it out works for me when the referer contains the word "orange". Just keep in mind that referers can be spoofed and it isn't a guarantee.

Iifr.ini Rewritecond

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.

Resources