Iifr.ini Rewritecond - .htaccess

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.

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]

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

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.

Sitewide redirects

I'm working on doing a site-wide redirect, while still maintaining a consistent url pattern.
http://www.site1.com/folder/page
should first redirect to
http://www.site1.com/redirectHandler?dest=folder/page
which would ultimately have a link to http://www.site2.com/folder/page
I can obviously code the last part, but since there are several hundred pages, I'm hoping someone can show how to do the first redirect via htaccess, instead of individual code on each page?
Did some investigation, here's what I found which does the trick (much simpler than I thought)
RewriteEngine on
RewriteRule ^(.*)$ http://www.site1.com/redirectHandler?dest=$1 [R=301,L]

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]

Resources