I'm trying to make a redirect rule which follows this logic:
source: www.site.com/businessinfo.asp?accommID=123
destination: www.site.com/redirect.php?type=property&id=123
My code:
RewriteRule ^/businessinfo.asp$ /redirect.php?type=property&id=$1 [QSA]
I've tried a dozen different variations, but can't get anywhere. Can anyone help?
This should work:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /businessinfo\.asp\?accommID=(.*)\ HTTP
RewriteRule ^ /redirect.php?type=property&id=%2 [R,L]
it should redirect www.site.com/businessinfo.asp?accommID=123 to www.site.com/redirect.php?type=property&id=123
Thanks for the above. For future reference, we solved this with a simple one-liner...
Redirect 301 /businessinfo.asp http://www.site.com/redirect.php
The querystring appends anyway, so we just rewrote the redirect script slightly to deal with accommID instead of ID.
Related
I've looked around the site for answers and followed a few examples but i'm still drawing a blank with this one.
I'm trying to get the following to redirect.
www.mydomain.com/?s=flat+roof+specifier+checklist
to
www.mydomain.com/resources/flat-roof-checklist/
My rewrite rule is below.
RewriteCond %{QUERY_STRING} s=flat+roof+specifier+checklist
RewriteRule ^(.*)$ /resources/flat-roof-checklist/? [L,R=301]
I think the issue im having is the "+" character.
if i change my URL to:
www.mydomain.com/?s=flat%20roof%20specifier%20checklist
and my rewrite condition to:
RewriteCond %{QUERY_STRING} s=flat%20roof%20specifier%20checklist
It works fine.
The problem with that is, the URL HAS to be www.mydomain.com/?s=flat+roof+specifier+checklist (with the + characters in there) as the business has already sent out communications with that particular url, so unfortunately i can't change it.
Am i missing some sort of regx to format my url beforehand.?
There's already a 301 redirect plugin running on the site but it doesn't work with that either.
Apologies as i'm fairly new to php,wordpress,htaccess etc.
Any help will be great appreciated.
You can place the pattern into a regex capture group and escape the plus signs, tested and working on my test server with the following
RewriteCond %{QUERY_STRING} (s=flat\+roof\+specifier\+checklist)
RewriteRule ^(.*)$ /resources/flat-roof-checklist/? [L,R=301]
I am looking for assistance with the redirection rules.
I have url www.example.com.au and I want the following redirections
https://www.example.com.au =>https://www.example.com.au
http://www.example.com.au =>https://www.example.com.au/page-2
I found the following .htaccess rules but its not working for me
RewriteEngine On
RewriteCond %{HTTP_HOST} www^example\.com.au [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%.
{HTTP_HOST}%www^example.com.au/page-2 [302 L]
can anyone please help me the correct rule.
I will be using the above rule for a WordPress site so do i need to paste the above rules at the bottom so that it doesn't overruled by other rewrite rule?
Thanks in advance.
For the first redirection it is impossible, it will create an infinite loop. You can not redirect an url on itself.
And for the second one ( http://www.example.com.au => https://www.example.com.au/page-2 ) you can do something like that
Redirect 301 / https://www.example.com.au/page-2
Pay attention to 301, it indicates that the redirection is permanent, I do not know if it is your goal.
But if your goals was to redirect http to https you can do something like that (put on the top of your .htaccess file):
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://www.example.com.au/$1 [R=301,L]
Or use a plugin like Really Simple SSL
Then you can define your rules to redirect one page to another before the rule above, like this:
Redirect 301 /old-page /new-page
I'm having a difficult time with this and hope you guys can help.
Using Helicon ISAPI Rewrite version 3.1.0.104 on our IIS server. I edit the http.conf file and have tried everything and still fail.
This is what I am trying to do:
Redirect this url:
https://www.domain.com/switch-by-version?version=2.8.5.2594
to:
https://test.domain.com/load/load.aspx?tver=2.8.5.2594
The version number at the end from the source url will change, and I need the target url to have the same version number at the end of its url as the example above shows.
I tried the following but it does not work:
RewriteCond %{QUERY_STRING} ^version=(\d\d?)\.(\d\d?)\.(\d\d?)\.(.*)$ [NC]
RewriteRule ^/switch-by-version(.*)$ https://test.domain.com/load/load.aspx?tver=%1 [R=307,NC,L]
Any help would be greatly appreciated!
Thanks.
If it's running in the equivalent context of an .htaccess, then the rule shouldn't start with a /. Here's a simpler version:
RewriteCond %{QUERY_STRING} ^version=(\d+\.\d+\.\d+(?:\..+)?)$ [NC]
RewriteRule ^switch-by-version/?$ https://test.domain.com/load/load.aspx?tver=%1 [R=307,NC,L]
I've searched answers on the forum but didn't worked for me.
I have rebuild an website using Wordpress and want to keep old urls.
old url:
/bingo/play-bingo-40/review?reviews_id=16
nwe url:
https://website.com/product/the-new-url-of-play-bingo-40/
I have tried this:
RewriteCond %{QUERY_STRING} ^reviews_id=([^&]+) [NC]
RewriteRule ^bingo/play-bingo-40/review https://website.com/product/the-new-url-of-play-bingo-40/? [R=301]
Any one?
You don't use anything from the query string, so you don't need to capture with a RewriteCond. You seem to use part of the request URL, so you must capture this one
RewriteRule ^bingo/(.+?)/review https://example.com/product/the-new-url-of-$1/? [R,L]
To learn more about mod_rewrite generally and regular expressions particularly, see http://httpd.apache.org/docs/current/rewrite/intro.html. Another good reference for regular expressions is http://www.regular-expressions.info/
It looks like this is a common issue since there are so many related questions here but I still have not found the solution after hours of searching...
I need to do many redirects via .htaccess for an old WordPress site. It uses URL's like this:
http://oldwpsite.com/?p=11
http://oldwpsite.com/?p=12
I need to redirect them something like this:
redirect 301 /?p=11 http://newwpsite.com/renting-a-scooter/ <--Does not work
redirect 301 /?p=12 http://newwpsite.com/scooter-tips/ <--Does not work
I have confirmed redirect does work with:
redirect 301 /xx.html http://newwpsite.com/ <--- Works
I tried many variations of RewriteEngine On, RewriteCond and RewriteRule but failed every time.
How can I do a redirect with question mark like the above?
This should redirect the two pages to where you want them to go:
RewriteEngine on
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /\?p=11\ HTTP
RewriteRule ^ http://newwpsite.com/renting-a-scooter? [R=301,L]
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /\?p=12\ HTTP
RewriteRule ^ http://newwpsite.com/scooter-tips? [R=301,L]