htaccess Redirect Code – Where Do I Add Redirect htaccess Code

Home Forums BulletProof Security Pro htaccess Redirect Code – Where Do I Add Redirect htaccess Code

This topic contains 9 replies, has 4 voices, and was last updated by Profile photo of AITpro Admin AITpro Admin 1 month, 1 week ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #417
    Profile photo of AITpro Admin
    AITpro Admin
    Keymaster

    I get asked this question a lot so I thought I would put together a basic guide to adding htaccess redirect code and where to add it in your root htaccess file.  htaccess redirects can be used to redirect old web pages to new web pages, old posts to new posts, old directories to new directories, and vice versa and of course to get rid of any 404 errors.  Basically you redirect anything to anything very quickly and easily with htaccess redirect code.  Since Redirect code can be put anywhere in your root .htaccess file then usually the best place for it is at the end or bottom of your root .htaccess file.

    If you have BPS or BPS Pro installed then add your redirect .htaccess code to this BPS Custom Code text box:   click the Save Root Custom Code button, go to the Security Modes page, click the Create secure.htaccess File AutoMagic button and activate Root Folder BulletProof Mode again.

    IMPORTANT NOTE!  If you have Go Daddy hosting then click the link below.  Go Daddy recently made some changes to their Servers that affect aliased domains when using RedirectMatch to redirect URLS (The Server change occurred somewhere around 7-10-2013).

    http://forum.ait-pro.com/forums/topic/go-daddy-redirect-htaccess-code-no-longer-working/

    So let’s start out with some simple examples and later I will add some more complex examples to this Topic.
    Let’s say you created a post called – my old post and you now want to redirect this post to a post called – my new post.
    The full URL to this old post is example.com/old-category/my-old-post
    The full URL to the new post is example.com/new-category/my-new-post

    I want to point out a couple of important things first.  You should always use the ^ and $ which mean the start and end of a URL path that you want to redirect and then use $1 which is called a back reference.  The back reference $1 will look for the $ in the first part of the RedirecMatch URL and is basically something like a placeholder or reference point or a “URL splicer”.  You can of course have many back references ($1, $2, $3, etc) in more complex htaccess code, but for simple RedirecMatch coding you will only have one back reference.  The reason you should always try to use a ^ starting point and a $ ending point is you could have similar URL’s that also would get redirected that you did not want to get redirected.  See the second example below.

    NOTE:  The “+” sign can also be a place holder for a back reference – Click to go to that section in this Forum Topic –  Back Referencing the Plus Sign.

    This is the htaccess code that you would use to permanently redirect the “old post” to the “new post” and to the new category as well.

    RedirectMatch 301 ^/old-category/my-old-post$ http://www.example.com/new-category/my-new-post$1

    Let’s say you did not add a ^ starting point and a $ ending point for this redirect below.

    RedirectMatch 301 /aitpro-blog/category/misc-projects/wordpress http://www.ait-pro.com/aitpro-blog/4349/misc-projects/wordpress-tips-tricks-fixes

    What would happen is that this redirect code would redirect all 3 of these posts below to the “wordpress-tips-tricks-fixes” post since you have not added a starting point and and ending point for the URL.

    /aitpro-blog/category/misc-projects/wordpress
    /aitpro-blog/category/misc-projects/wordpress-blah1
    /aitpro-blog/category/misc-projects/wordpress-blah2

    By adding your ^ starting point and the $ ending point you are saying STOP at the $ sign and do not look any further since this is the end point of the URL you want to redirect.

    This redirect below will only redirect – /aitpro-blog/category/misc-projects/wordpress to http://www.ait-pro.com/aitpro-blog/4349/misc-projects/wordpress-tips-tricks-fixes/ and the blah1 and blah2 examples above would not be redirected.

    RedirectMatch 301 ^/aitpro-blog/category/misc-projects/wordpress$ http://www.ait-pro.com/aitpro-blog/4349/misc-projects/wordpress-tips-tricks-fixes/$1

    Here is quick example of using the $1 back reference in a way that makes it very clear about how it works.  Notice in this example that the back reference is not at the end of the RewriteRule and is actually at the beginning.  There are times when using the $1 back reference should not be used because it will create another redirect that will be incorrect and generate a 404 error.  When NOT to use the $1 back reference.

    Stripping, adding or replacing Query Strings & redirects:

    Important Notes:  If you have a WordPress site then this code needs to be inside of the WordPress Rewrite Loop. See this forum topic for how to add this code in BPS Custom Code: http://forum.ait-pro.com/forums/topic/i-had-a-working-set-of-redirects-but-not-now/#post-24703  Query Strings are cached by the Google Chrome browser and probaby all other browsers so if you are changing things with your Query String htaccess code then you should clear your browser cache in-between each change you make to ensure you are seeing current htaccess code processing and not previous/past htaccess code processing.

    This code says that if a Request for this URL|URI /blah/testing-appending-query-string/(.*) – (means match anything) is made then Rewrite this Request and the back reference will start from where the $ sign ends in the first part of the RewriteRule – you end up with this URL – /blah/testing-appending-query-string/?keywords=[keyword] . The URL|URI and Query String are “spliced”/added together by using $1.

    RewriteEngine On
    RewriteBase /blah/
    RewriteCond %{REQUEST_URI} ^/blah/testing-appending-query-string/(.*) [NC]
    RewriteRule ^(.*)$ $1?keywords=[keyword] [R=302]

    Strips the do=contactus and do=detailpage Query Strings from the URL|URI:

    # Strips the do=contactus and do=detailpage Query Strings from the URL|URI
    RewriteCond %{QUERY_STRING} ^do=contactus$ [NC,OR]
    RewriteCond %{QUERY_STRING} ^do=detailpage(.*)$ [NC]
    RewriteRule ^(.*)$ $1? [R=301,L]

    Replaces Query Strings: do=contactus and do=detailpage with Query string: ?keywords=[keyword]:

    # Replaces Query Strings: do=contactus and do=detailpage with Query string: ?keywords=[keyword]
    RewriteCond %{QUERY_STRING} ^do=contactus$ [NC,OR]
    RewriteCond %{QUERY_STRING} ^do=detailpage(.*)$ [NC]
    RewriteRule ^(.*)$ $1?keywords=[keyword] [R=301,L]

    Strips all Query Strings that start with do= ONLY if the Request URI is classifieds/ and redirects to the /ads/ URI:  http://www.example.com/<strong>classifieds/?do=detailpage&cat=3&id=14 to <code>http://www.example.com/<strong>ads/ </strong>

    # Redirects ONLY if the URI is classifieds/ and Strips the do= Query Strings
    # from the destination /ads/ URL|URI
    RewriteCond %{QUERY_STRING} ^do=(.*)$ [NC]
    RewriteRule ^classifieds/$ http://www.example.com/ads/$1? [R=301,L]

    Individual explicit and dynamic redirect rules based on Query String matches and stripping Query Strings from the destination URL|URI.
    Will redirect these URL’s and Query Strings:

    http://www.example.com/index.php?option=com_k2&view=item&id=7377
    http://www.example.com/index.php?option=com_k2&view=item&id=7378
    To these destination URL’s|URI’s & strip the Query Strings:
    http://www.example.com/artigos/7377/
    http://www.example.com/artigos/7378/

    # Individual explicit redirect rules based on exact matching URI|Query String parameters
    # $1? Strip the option=com_k2&view=item&id=7377 Query String from the destination URI
    RewriteCond %{QUERY_STRING} ^option=com_k2&view=item&id=7377$ [NC]
    RewriteRule ^(.*)$ /artigos/7377/$1? [R=301,L]
    RewriteCond %{QUERY_STRING} ^option=com_k2&view=item&id=7378$ [NC]
    RewriteRule ^(.*)$ /artigos/7378/$1? [R=301,L]
    
    # Dynamically redirect all matching Query Strings to equivalent URI
    # %2 match and redirect to equivalent 4 digit number URI
    # $1? Strip the option=com_k2&view=item&id= portion of the Query String from the destination URI
    RewriteCond %{QUERY_STRING} ^(option=com_k2&view=item&id+)=([0-9]{4}+)$ [NC]
    RewriteRule ^(.*)$ /artigos/%2/$1? [R=301,L]

    Ok for now here are some Redirects that are used on the AITpro Blog site to correct 404 errors that were showing up in Google Webmaster Tools.

    # Redirect 404 errors that show up in Google Webmaster Tools
    RedirectMatch 301 ^/aitpro-blog/misc-projects/funny-stuff/$ http://www.ait-pro.com/aitpro-blog/category/misc-projects/$1
    RedirectMatch 301 ^/aitpro-blog/category/misc-projects/wordpress$ http://www.ait-pro.com/aitpro-blog/4349/misc-projects/wordpress-tips-tricks-fixes/$1
    RedirectMatch 301 ^/aitpro-blog/website-metrics-posting-form/$ http://www.ait-pro.com/aitpro-blog/
    RedirectMatch 301 ^/aitpro-posting-form/activation-key-verification/$ http://www.ait-pro.com/aitpro-blog/
    RedirectMatch 301 ^/aitpro-blog/tag/bps-pro-php.ini$ http://www.ait-pro.com/aitpro-blog/
    RedirectMatch 301 ^/aitpro-blog/tag/modify-bps-htaccess-file$ http://www.ait-pro.com/aitpro-blog/
    RedirectMatch 301 ^/aitpro-blog/tag/custom-403$ http://www.ait-pro.com/aitpro-blog/
    RedirectMatch 301 ^/aitpro-blog/tag/average-wordpress$ http://www.ait-pro.com/aitpro-blog/
    RedirectMatch 301 ^/aitpro-blog/tag/bulletproof-security-pro-php$ http://www.ait-pro.com/aitpro-blog/
    RedirectMatch 301 ^/aitpro-blog/tag/as3$ http://www.ait-pro.com/aitpro-blog/
    RedirectMatch 301 ^/aitpro-blog/tag/apache-fastcgi$ http://www.ait-pro.com/aitpro-blog/
    RedirectMatch 301 ^/aitpro-blog/tag/bullet$ http://www.ait-pro.com/aitpro-blog/
    RedirectMatch 301 ^/aitpro-blog/tag/free-flash$ http://www.ait-pro.com/aitpro-blog/
    RedirectMatch 301 ^/aitpro-blog/tag/translate-wordpress$ http://www.ait-pro.com/aitpro-blog/
    RedirectMatch 301 ^/aitpro-blog/tag/403$ http://www.ait-pro.com/aitpro-blog/
    RedirectMatch 301 ^/aitpro-blog/tag/bps-pro-php$ http://www.ait-pro.com/aitpro-blog/
    RedirectMatch 301 ^/aitpro-blog/tag/add-a-banner$ http://www.ait-pro.com/aitpro-blog/
    RedirectMatch 301 ^/aitpro-blog/tag/wordpress-website-under$ http://www.ait-pro.com/aitpro-blog/
    RedirectMatch 301 ^/aitpro-blog/tag/translate-bullet$ http://www.ait-pro.com/aitpro-blog/
    RedirectMatch 301 ^/aitpro-blog/tag/login$ http://www.ait-pro.com/aitpro-blog/login/
    RedirectMatch 301 ^/aitpro-blog/tag/best-custom$ http://www.ait-pro.com/aitpro-blog/
    RedirectMatch 301 ^/aitpro-blog/tag/crt-television-history\.\.$ http://www.ait-pro.com/aitpro-blog/tag/crt-television-history-and-facts/
    RedirectMatch 301 ^/aitpro-blog/tag/electronic-computer-his\.\.$ http://www.ait-pro.com/aitpro-blog/tag/electronic-computer-history-and-facts/

     

    # Redirect old website security testing posts that were generating 404 errors in Google Webmaster Tools

    # Redirects a URL starting out with numbers 0-9 and this is a range {2,5} which means match a range of 2 to 5 numbers
    # example 12, 201, 4352, 10300 would all match the range, but a single number like 4 or numbers over 5 number characters like 209467 (6 number characters) would not match the range.
    # this URL would be redirected - /45/website-security-842/ to /wordpress-testing-website/category/website-security-testing/
    RedirectMatch 301 ^/wordpress-testing-website/[0-9]{2,5}/website-security-[0-9]{2,5}/$ http://www.ait-pro.com/wordpress-testing-website/category/website-security-testing/
    # this URL would be redirected - /678/series-4/ to /wordpress-testing-website/category/series-testing/
    RedirectMatch 301 ^/wordpress-testing-website/[0-9]{2,5}/series-[0-9]{1,5}/$ http://www.ait-pro.com/wordpress-testing-website/category/series-testing/
    RedirectMatch 301 ^/wordpress-testing-website/wordpress-testing-website/author/admin/page/(.*)$ http://www.ait-pro.com/wordpress-testing-website/
    RedirectMatch 301 ^/wordpress-testing-website/category/website-security-testing/page/(.*)$ http://www.ait-pro.com/wordpress-testing-website/category/website-security-testing/
    RedirectMatch 301 ^/wordpress-testing-website/category/series-testing/page/(.*)$ http://www.ait-pro.com/wordpress-testing-website/category/series-testing/

    When NOT to use the $1 back reference in redirect code

    If the $1 back reference is used to redirect this old post URL that was deleted from the aitpro-blog site…

    http://www.ait-pro.com/aitpro-blog/wordpress-tips-tricks-fixes/bulletproof-htaccess-file-code-wordpress-bulletproof-htaccess-code/

    …to a new category on the blog site then a 404 error will happen because the $1 back reference is “splicing” the URL together and redirecting to a non-existent URL.

    RedirectMatch 301 ^/aitpro-blog/wordpress-tips-tricks-fixes/bulletproof-htaccess(.*)$ http://www.ait-pro.com/aitpro-blog/category/misc-projects/wordpress-tips-tricks-fixes/$1

    The result of using the $1 back reference in the above redirect code is that you now end up with this “spliced” URL that will of course generate a 404 because this URL does not really exist.  Notice how the yellow hightlighted part of the new redirected URL is starting from the end of this part of the RedirectMatch code – /bulletproof-htaccess(.*) and then creates a new “spliced” URL starting from the end of the (.*) which is being back referenced by $1 and the rest or URL shown above in Blue highlight is now spliced / added to the new non-existent URL.

    http://www.ait-pro.com/aitpro-blog/category/misc-projects/wordpress-tips-tricks-fixes/-file-code-wordpress-bulletproof-htaccess-code/

    The correct way to redirect the old post URL:  If the $1 back reference is not used…

    RedirectMatch 301 ^/aitpro-blog/wordpress-tips-tricks-fixes/bulletproof-htaccess(.*)$ http://www.ait-pro.com/aitpro-blog/category/misc-projects/wordpress-tips-tricks-fixes/

    …Then the old post URL that was deleted from the aitpro-blog site will be redirected to the correct new category – category/misc-projects/wordpress-tips-tricks-fixes/ – so that a 404 error will not be generated.

    Other Examples:

    RedirectMatch 301 ^/wordpress-testing-website/68/(.*)$ http://www.ait-pro.com/wordpress-testing-website/
    RedirectMatch 301 ^/wordpress-testing-website/2909/(.*)$ http://www.ait-pro.com/wordpress-testing-website/
    RedirectMatch 301 ^/wordpress-testing-website/2911/(.*)$ http://www.ait-pro.com/wordpress-testing-website/
    RedirectMatch 301 ^/wordpress-testing-website/1/(.*)$ http://www.ait-pro.com/wordpress-testing-website/
    RedirectMatch 301 ^/wordpress-testing-website/97/(.*)$ http://www.ait-pro.com/wordpress-testing-website/
    RedirectMatch 301 ^/wordpress-testing-website/93/(.*)$ http://www.ait-pro.com/wordpress-testing-website/
    RedirectMatch 301 ^/wordpress-testing-website/Home$ http://www.ait-pro.com/wordpress-testing-website/
    RedirectMatch 301 ^/wordpress-testing-website/menu-(.*)$ http://www.ait-pro.com/wordpress-testing-website/
    RedirectMatch 301 ^/wordpress-testing-website/229/(.*)$ http://www.ait-pro.com/wordpress-testing-website/
    RedirectMatch 301 ^/wordpress-testing-website/1226/(.*)$ http://www.ait-pro.com/wordpress-testing-website/
    RedirectMatch 301 ^/wordpress-testing-website/87/(.*)$ http://www.ait-pro.com/wordpress-testing-website/
    RedirectMatch 301 ^/wordpress-testing-website/104/(.*)$ http://www.ait-pro.com/wordpress-testing-website/
    RedirectMatch 301 ^/wordpress-testing-website/55/(.*)$ http://www.ait-pro.com/wordpress-testing-website/
    RedirectMatch 301 ^/wordpress-testing-website/about/menu-(.*)$ http://www.ait-pro.com/wordpress-testing-website/
    RedirectMatch 301 ^/wordpress-testing-website/comment-page-1/Home(.*)$ http://www.ait-pro.com/wordpress-testing-website/
    RedirectMatch 301 ^/wordpress-testing-website/tag/beef/YAPB(.*)$ http://www.ait-pro.com/wordpress-testing-website/
    RedirectMatch 301 ^/wordpress-testing-website/tag/tim-thumb/TimThumb(.*)$ http://www.ait-pro.com/wordpress-testing-website/

    Back Referencing the “+” / Plus Sign

    Back Referencing the “+” / Plus sign works the same as back referencing a $ / Dollar sign in that you are “splicing” URL’s using a placeholder and a back reference $1, $2, $3, etc.  This is a much more sophisticated example of .htaccess redirect coding than the examples above.  There are assumed conditions in htaccess code and those assumed conditions are “if” and “and” unless you specify otherwise by using .htaccess flags such as [OR] which is exactly what it looks like and means “or” instead of “and”.  Breaking down the code below it translates to something like this:  if the first condition is matched up to the first back reference of $1 then redirect that URL.  if the second condition is matched up to the second back reference $2 then redirect that URL, etc etc etc.

    The Regex for this bit of code ([^/]+) means look at this group – a group is enclosed in round brackets ( and ) (aka parenthesis singular/parentheses plural).  The square brackets with the caret/circumflex character [^/] means match any single character that is not in the set (a set is everything inside of [ ] square brackets).  So in this case it is saying match anything, but the forward slash / which would mean you would be in another level of the URL.  /first-level/second-level/etc.  If you are in the first level of the URL then redirect or rewrite it, if you are in the second level or the URL then redirect or rewrite it, etc etc etc.  And since the caret/circumflex is used inside of the set it has a different meaning then when used at the beginning of this code below.  Outside of a set the caret/circumflex means the start of a condition and the $ sign means the end of a condition.

    This example below shows how to redirect old HTML pages to a new WordPress site and have those redirects point to Posts.

    Source:  http://stackoverflow.com/questions/11926237/redirecting-old-html-page-to-new-without-html-extension-page

    RedirectMatch 301 ^/([^/]+)/([^/.]+)\.html$ /$1/$2/ 
    RedirectMatch 301 ^/([^/]+)/([^/]+)/([^/.]+)\.html$ /$1/$2/$3/ 
    
    Or if you need to limit it by hosts, you can use mod_rewrite: 
    
    RewriteCond %{HTTP_HOST} sitename.com [NC] 
    RewriteRule ^([^/]+)/([^/.]+)\.html$ /$1/$2/ [R=301,L] 
    
    RewriteCond %{HTTP_HOST} sitename.com [NC] 
    RewriteRule ^([^/]+)/([^/]+)/([^/.]+)\.html$ /$1/$2/$3/ [R=301,L]
    • This topic was modified 8 months, 1 week ago by Profile photo of AITpro Admin AITpro Admin.
    • This topic was modified 8 months, 1 week ago by Profile photo of AITpro Admin AITpro Admin.
    • This topic was modified 8 months, 1 week ago by Profile photo of AITpro Admin AITpro Admin.
    • This topic was modified 8 months, 1 week ago by Profile photo of AITpro Admin AITpro Admin.
    • This topic was modified 8 months, 1 week ago by Profile photo of AITpro Admin AITpro Admin.
    • This topic was modified 8 months, 1 week ago by Profile photo of AITpro Admin AITpro Admin.
    • This topic was modified 8 months, 1 week ago by Profile photo of AITpro Admin AITpro Admin.
    • This topic was modified 8 months, 1 week ago by Profile photo of AITpro Admin AITpro Admin.
    • This topic was modified 1 month ago by Profile photo of AITpro Admin AITpro Admin.
    • This topic was modified 1 month ago by Profile photo of AITpro Admin AITpro Admin.
    #24917
    Profile photo of jenni101
    jenni101
    Participant

    Your advice would be appreciated regarding redirects for content that is for logged in members only – as the google bot sees it as a 404 error! I now have 441 of these errors, but as the content is real (just protected) I’m not sure what to do. Is there a way to tell Google that it’s private? We still have some pages that are public but most pages, posts, uploaded images etc are not.

    many thanks.

    Update for anyone interested: since digging a little deeper in Google Search Console (ex webmaster tools) it seems that most of the 404 error were from links from an old html sitemap I’d submitted: attachment-sitemap.xml which i no longer use. So I’ve fixed it by resubmitting my correct html sitemaps and I’m hoping that the bots will now realise the old one doesn’t exist.

    • This reply was modified 7 months, 4 weeks ago by Profile photo of jenni101 jenni101. Reason: update + provisional fix
    #28555
    Profile photo of DKK
    DKK
    Participant

    I am having an issue with important redirect rules which I need to set-up. Well, “may have an issue”, as I am unsure how the syntax should be, and thus don’t want to crash my site a dozen times trying to get it right.

    Presently I have redirect rules in my root .htaccess that look like…and they all work without a hitch.

    rewriterule ^old-version-page/ https://web.site/path/to/new-page-version/ [R=301,L]
    rewriterule ^another/old-example/page/ https://web.site/path/for_some-other/new-page/ [R=301,L]

    But the ones which I have to configure now have individual query strings. Examples:

    old-site.com/?p=164
    old-site.com/?p=6320
    old-site.com/?p=2357

    And ‘no’, I cannot use their alt. URLs. Each old page number would be going to a unique new page (which have different page numbers; and ‘yes’, I know that I need to check for numerical overlaps and correct such issues first). Now my problem is concerning what syntax to use for the redirects, as I know that certain characters (ex. ‘?’) must be escaped or substituted for everything to go right (rather than everything turning dead-white per se). I saw how to set up redirects that involve groups of query strings (ex. redirecting all pages with “?p=” to wherever), but not how to do so for specific queries (unless I’ve missed it somewhere).

    Thanks in advance.

    • This reply was modified 1 month, 3 weeks ago by Profile photo of AITpro Admin AITpro Admin.
    #28557
    Profile photo of AITpro Admin
    AITpro Admin
    Keymaster

    Yep, Query Strings are tricky due to the way all Browsers are designed to interpret/handle/process Query Strings, which start with the question mark to signify processing/handling of a Query String instead of a Browser seeing the question mark as a literal character in a URL|URI.  So the htaccess code that you want to use is this example code below:

    Strips all Query Strings that start with do= ONLY if the Request URI is classifieds/ and redirects to the /ads/ URI:  http://www.example.com/classifieds/?do=detailpage&cat=3&id=14 to http://www.example.com/ads/ 

    # Redirects ONLY if the URI is classifieds/ and Strips the do= Query Strings
    # from the destination /ads/ URL|URI
    RewriteCond %{QUERY_STRING} ^do=(.*)$ [NC]
    RewriteRule ^classifieds/$ http://www.example.com/ads/$1? [R=301,L]

    If you are just trying to redirect all old URL’s|URI’s to one place/any new URL|URI on the new site just to get rid of any/all 404 errors from the old site then you can just use this code: RedirectMatch 301 ^/(.*)$ http://www.example.com/

    If you are trying to redirect old URL’s|URI’s to new specific URL’s|URI’s your actual code would probably be something like this and since this code is going to be in the htaccess file on the “old site” then you do not have to factor in that it would impact/affect the URI’s on the new site.

    RewriteCond %{QUERY_STRING} ^p=164$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/new-page-or-post-url/$1? [R=301,L]
    RewriteCond %{QUERY_STRING} ^p=6320$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/another-new-page-or-post-url/$1? [R=301,L]
    RewriteCond %{QUERY_STRING} ^p=2357$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/some-other-new-page-or-post-url/$1? [R=301,L]
    • This reply was modified 1 month, 3 weeks ago by Profile photo of AITpro Admin AITpro Admin.
    • This reply was modified 1 month, 3 weeks ago by Profile photo of AITpro Admin AITpro Admin.
    #28567
    Profile photo of DKK
    DKK
    Participant

    Thank you for your quick & detailed response. The 3rd/last portion you showed looked quite similar to the format I had constructed that I was going to try if you hadn’t replied that was based on examples I found on different forums, but yet you saying that such would be for the “old site” threw me so-to-speak.

    I should have been a bit more specific in my examples and my situation; which was my fault indeed.

    I had managed a website ending in .com that was on shared hosting via GoDaddy.

    Later, the owner purchased their own VPS and a .org version of the Domain (and thus had a .com & .org version of the same Website name –though the actual sites were structured differently). After a period of time, the .com website hosting was purposely let-go (while keeping the domain of course). Thus, the .com needed/needs to be synced to the .org when it comes to all similar/parallel products, pages, categories, links, etc. (as the .com had already made a name for itself on search engines, forums, and review boards).

    When it comes to general redirection, the .com has already been made into a DNS alias & has an overall forwarding-config going to the .org set-up via GoDaddy’s DNS/Domain services (and it has been working perfectly). But for old page names & numbers which are different on the new .org site, 400’s are of course thrown unless proper redirects are put in place.

    Via viewing this forum, I was able to correct URL name mismatches. But it is the "http://website.com/?p=####" to "https://website.org/page/of-something/" sort of mismatch that I’m having issues with. (And yes, the .com was HTTP and the .org is HTTPS; though I have yet to see an issue with that.)

    Thus, the I cannot put the code into the htaccess file on the “old site”, as the old site technically doesn’t exist anymore; well, actually, technically speaking, the .org’s htaccess is now the .com’s htaccess seeming that the one is now the alias of the other…

    I’m not sure if I’ve just clarified that your code should in-fact still work in my situation or not, but I rather be safe than sorry.

    Lastly, just to show in-case it may be of aid, here is the format I was planning on using based on another example:

    # Rewrite rules per example of:
    #RewriteEngine On
    #RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
    #RewriteRule ^(.*)$ http://www.sample-site.com/path/to-proper/page/ [R=302,L]
    
    RewriteEngine On
    
    RewriteCond %{QUERY_STRING} ^p=([167]*)$
    RewriteRule ^/$ https://website.org/new-page/ [R=301,L]
    RewriteCond %{QUERY_STRING} ^p=([3048]*)$
    RewriteRule ^/$ https://website.org/topic/sub-topic/page/ [R=301,L]
    RewriteCond %{QUERY_STRING} ^p=([3068]*)$
    RewriteRule ^/$ https://website.org/category/subcategory/product/index/page/ [R=301,L]
    # END Custom Redirects for Query Strings
    • This reply was modified 1 month, 3 weeks ago by Profile photo of DKK DKK. Reason: 2 Typos fixed
    • This reply was modified 1 month, 3 weeks ago by Profile photo of AITpro Admin AITpro Admin.
    #28570
    Profile photo of AITpro Admin
    AITpro Admin
    Keymaster

    Not sure if you are asking a question or not of if you are saying you already have a solution or you are saying that you are going to try your solution.  In any case, just let me know if your solution does not work and I will try to assist you further.

    • This reply was modified 1 month, 3 weeks ago by Profile photo of AITpro Admin AITpro Admin.
    #28572
    Profile photo of DKK
    DKK
    Participant

    lol. My bad. Seems in my attempt to clarify my issue, I sealed it with confusion.  I am asking whether or not your solution of

    RewriteCond %{QUERY_STRING} ^p=164$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/new-page-or-post-url/$1? [R=301,L]
    RewriteCond %{QUERY_STRING} ^p=6320$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/another-new-page-or-post-url/$1? [R=301,L]
    RewriteCond %{QUERY_STRING} ^p=2357$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/some-other-new-page-or-post-url/$1? [R=301,L]

    would still be applicable for my situation even though it would be going in the ‘new’ site’s htaccess rather than the ‘old’?

    (I meant to end my last post with that.)

    • This reply was modified 1 month, 3 weeks ago by Profile photo of AITpro Admin AITpro Admin.
    #28574
    Profile photo of AITpro Admin
    AITpro Admin
    Keymaster

    Ok so if understand correctly you have DNS pointing all URL’s from the old site to the new site so the URL’s would be this:  new-site.org/?p=164. If that is the case then the code I posted above should work in the new site’s root htaccess file, but there could be a problem with WordPress internal rewriting of p= URL’s (posts and pages).

    If not and the old site URL’s are this: old-site.com/?p=164 then the only way to redirect the old site URL’s to the new site URL’s would be to recreate the old site folder and put a new htaccess file in it with the code I posted above to redirect the old site URL’s that go to the old site and not the new site. The logic is this: the old site URL’s send someone to the old site that existed before and do not send someone to the new site so adding htaccess redirect code on the new site would not do anything since the URL’s do not go/point to this new site.

    • This reply was modified 1 month, 3 weeks ago by Profile photo of AITpro Admin AITpro Admin.
    #28769
    Profile photo of D Joseph
    D Joseph
    Participant

    [Topic has been merged into this relevant Topic]
    Hi, I haven’t worked on websites or touched the BPS  Pro in almost 2 years.

    With the WPTwin, I recently cloned a website that has BPS Pro Version 5.1.9, to a new site. I just cloned the whole thing, uninstalled BPS Pro on the new site through WP admin, and then updated WP to 4.4.2. (Although I still see some BPS folders in Filezilla after I uninstalled the BPS Pro.) I want to do a fresh install on the new site but I need to do this first:

    I need to redirect the 1st domain to the new website. When I tried to do that in CPanel, it wouldn’t let me. I assume it’s because of the BPS Pro security. Can you tell me please, or point me to a link, to the directions on what I need to do for that? Thanks!

    • This reply was modified 1 month, 1 week ago by Profile photo of AITpro Admin AITpro Admin.
    • This reply was modified 1 month, 1 week ago by Profile photo of AITpro Admin AITpro Admin.
    #28772
    Profile photo of AITpro Admin
    AITpro Admin
    Keymaster

    This Redirect htaccess code below in an htaccess file in the old site’s folder would redirect all old site pages and posts to identical matching pages and posts with the same identical structure on the new site/domain.

    RedirectMatch 301 ^/$ http://www.newdomain.com/$1

    For some web hosts you need to include the folder name where the website is physically installed. olddomain.com would be the name of the folder and not the URL|URI name.

    RedirectMatch 301 ^/olddomain.com$ http://www.newdomain.com/$1

    See this forum topic for recommendations when migrating/moving/cloning websites:  http://forum.ait-pro.com/forums/topic/migrating-moving-or-cloning-websites/#post-20407

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.