Jump to content

Old CMS was in /site/...how best to redirect requests?


MarcC
 Share

Recommended Posts

I upgraded an older CMS that was located in /site/. Google (and several address bar auto-completers at my client's office) will send people to example.com/site/ instead of example.com. What's a good way to redirect those requests without messing with ProcessWire's stuff in /site/?

Link to comment
Share on other sites

To redirect requests for just "/site/", you could do something like this in your main PW .htaccess file (after the 'RewriteEngine On' line):

RewriteRule ^site/?$ / [R=301,NC,L]

That would redirect a request for /site or /site/ to the root.

If you have to account for additional URLs off of /site/, then you'd want to do something like this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^site/(.*)$ /$1 [R=301,L,QSA]

That would redirect requests for /site/[any file or path that doesn't exist on the disk] to the same path off of root rather than /site/.

Link to comment
Share on other sites

Thanks Ryan--I tried the 2nd, since there are files used by the templates in /site/ but that still results in a "forbidden" for people who go to example.com/site. Any idea why?

Not sure. It seems to work here -- This was one I actually tested before posting. The only thing I can think of is to make sure that you are putting those directives immediately after the "RewriteEngine On" and not after some of ProcessWire's directives. Though sounds like you may have already found another solution for this? Though admittedly I'm confused as to why that would work, because "site" is a directory that should exist, and thus PW shouldn't be getting control for a request like "/site/".

Link to comment
Share on other sites

Ryan, thanks for your reply. There is no longer a directory called "site", as it was the previous website's location and is now gone. That's why the code is working. Fortunately I'll eventually be able to yank that code, as search engines pick up the new URLs. I did follow your directions with .htacccess but for whatever reason it didn't work. I'm not a big fan of their web host...maybe that's part of it? Dunno.

Link to comment
Share on other sites

There is no longer a directory called "site", as it was the previous website's location and is now gone.

But there should now be one as a result of your ProcessWire installation, which uses /site/ for all your site-specific files.

I did follow your directions with .htacccess but for whatever reason it didn't work. I'm not a big fan of their web host...maybe that's part of it? Dunno.

You may be right, it is possible there is something host specific. But just to confirm, it sounds like you found a solution that still works by using your http404 page? Assuming that's working, I would change your header() call to a $session->redirect() call, just to enforce it as a 301 'permanent' redirect, which will be preferable from an SEO perspective.

$session->redirect("http://www.communityfound.org");
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...