dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: URL Forwarding

  1. #1
    Join Date
    Feb 2010
    Posts
    92

    URL Forwarding

    Ok, I've had a website for 6 years. Has a blog, forum, etc. We got around 200k social media fans with a million links to old posts and images on the site. While social media was strong the rest of the site has slowly diminished. I did something drastic... move EVERYTHING to a subdomain of the site such as old.boguswebsite.com so that stuff can be looked back on for a while at minimum and old links can still be viewed. While I'm starting pretty much 100% fresh with a brand new wordpress install (new ideas) etc in the main domains place.

    I've spent the day correcting any broken templates etc after the move so it all looks good again at that old subdomain. But now I've got no idea how to handle the permanent forwarding to make all my urls work and google not freak out on me...LOL. I'm hoping there is a very easy htaccess code or something. Maybe a way to say all old urls prior to today are forwarded to old.boguswebsite.com/remainingnormalurls. Then all new and fresh stuff just continues like a fresh site. Am I in a dreamland here or is there an easy fix?

    Sorry if I should have been calling it 'redirect' but you get my point

    Thanks!

  2. #2
    Join Date
    May 2017
    Posts
    6
    You'll need something like this in your root .htaccess file of your primary site (the one where the content used to be):

    Code:
    <IfModule mod_rewrite.c>
    RewriteRule ^forum/(.*)$ http://old.boguswebsite.com/forum/$1 [R=301,L]
    </IfModule>
    That will do a permanent redirect of all URLs in the forum directory to the same URL on your archive subdomain.

    That solution assumes the all the old URLs were in a single directory. If they weren't, it gets a bit more complicated, but it's still doable.

    And also of note is that mod_rewrite calls in .htaccess files only work a certain number of directories deep. So if your server is set to 3 directories deep and the URL is 4 directories deep, then your mod_rewrite rule won't execute. [There are workarounds for that too, if it's an issue.]

    OR (slightly better)… Create an empty directory ("/forum/") where the URLs used to come from and put this in the .htaccess in that directory…

    Code:
    <IfModule mod_rewrite.c>
    RewriteRule ^(.*)$ http://old.boguswebsite.com/forum/$1 [R=301,L]
    </IfModule>
    That has two advantages: 1) it only executes for URLs in that directory, and 2) it gives you one more level of directory depth.

  3. #3
    Join Date
    Feb 2010
    Posts
    92
    I need all the old urls forwarded from not just /forum/ but also my main WordPress installation from the very base of my site. I'm guessing that's where it gets really complicated...lol. So all old stuff from mybogussite.com/mybogusblogpostorpageorauthorlink etc needs to forward to old.mybogussite.com/mybogusblogpostorpageorauthorlink

    Then mybogussite.com/newpostorpageetc needs to stay put and not be forwarded.

    Quote Originally Posted by jay5r View Post
    You'll need something like this in your root .htaccess file of your primary site (the one where the content used to be):

    Code:
    <IfModule mod_rewrite.c>
    RewriteRule ^forum/(.*)$ http://old.boguswebsite.com/forum/$1 [R=301,L]
    </IfModule>
    That will do a permanent redirect of all URLs in the forum directory to the same URL on your archive subdomain.

    That solution assumes the all the old URLs were in a single directory. If they weren't, it gets a bit more complicated, but it's still doable.

    And also of note is that mod_rewrite calls in .htaccess files only work a certain number of directories deep. So if your server is set to 3 directories deep and the URL is 4 directories deep, then your mod_rewrite rule won't execute. [There are workarounds for that too, if it's an issue.]

    OR (slightly better)… Create an empty directory ("/forum/") where the URLs used to come from and put this in the .htaccess in that directory…

    Code:
    <IfModule mod_rewrite.c>
    RewriteRule ^(.*)$ http://old.boguswebsite.com/forum/$1 [R=301,L]
    </IfModule>
    That has two advantages: 1) it only executes for URLs in that directory, and 2) it gives you one more level of directory depth.

  4. #4
    Join Date
    May 2017
    Posts
    6
    Quote Originally Posted by blue_vision View Post
    I need all the old urls forwarded from not just /forum/ but also my main WordPress installation from the very base of my site. I'm guessing that's where it gets really complicated...lol. So all old stuff from mybogussite.com/mybogusblogpostorpageorauthorlink etc needs to forward to old.mybogussite.com/mybogusblogpostorpageorauthorlink

    Then mybogussite.com/newpostorpageetc needs to stay put and not be forwarded.
    You can only use mod_rewrite to forward URLs that you can define in some way. If you had Wordpress in the root directory before and you have a fresh copy in there now, then then it's much more complicated because Wordpress handles all unknown URLs. Assuming you have .htaccess set up for "pretty urls" you'll have something like this in your .htaccess file…

    Code:
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    What that's saying is that anything that can't be found on disk should be served by /index.php which is WordPress' main script file that calls all the other code in WordPress. Once you've passed it off to WordPress there's not a lot you could do. I suppose you could write a WordPress extension that gets triggered on a 404 and redirect to the archive server. But that's not something I can describe off the top of my head. But it's probably doable.

  5. #5
    Join Date
    May 2017
    Posts
    1
    You can go to file .htaccess to redirect for URL.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles