Jump to content

htaccess: Redirect pages to subfolders


teo74
 Share

Recommended Posts

Hi all,

I'm trying to redirect pages like:

providers/
   provider1
   provider2
   provider3
   provider4

to:

region-provider/
   region1/
      providerName1
      providerName4
   region2/
      providerName2
      providerName3

I put on top of ProcessWire's .htaccess file:

RewriteEngine On
Redirect 301   /providers/provider1    /region-provider/region1/providerName1
Redirect 301   /providers/provider2    /region-provider/region2/providerName2

...and so on,

and it does redirects, but I get:

/region-provider/region2/providerName2?it=providers/provider2

which triggers a 404 error.

If I delete "?it=providers/provider2" the page is found, so it's ok, but how can I get rid of "?it=[old-path]" ?

I'm not sure if the syntax  or   the position of my redirect rules within ProcessWire' .htaccess file is correct .

I also tried to make a phisical directory into web root called "providers" and redirect from there but no success.

Please helpp!!

Thank you!

Link to comment
Share on other sites

Better to use mod_rewrite:

RewriteEngine On
RewriteRule ^providers/provider1$ /region-provider/region1/providerName1 [R=301,L]
RewriteRule ^providers/provider2$ /region-provider/region1/providerName2 [R=301,L]

Does providers/provider1 actually exist in the ProcessWire page tree?

Link to comment
Share on other sites

Thank you Mike!

It works!, although my assets aren't loaded (maybe because my PW installation is under a /test/ directory). I added my rules just before:

  RewriteRule /providers/provider1    /test/region-provider/region1/providerName1 [R=301,L]  

  # ----------------------------------------------------------------------------------------------- 
  # Pass control to ProcessWire if all the above directives allow us to this point.
  # For regular VirtualHosts (most installs)
  # ----------------------------------------------------------------------------------------------- 
  RewriteRule ^(.*)$ index.php?it=$1 [L,QSA]

  # ----------------------------------------------------------------------------------------------- 
  # 500 NOTE: If using VirtualDocumentRoot: comment out the one above and use this one instead.
  # ----------------------------------------------------------------------------------------------- 
  # RewriteRule ^(.*)$ /index.php?it=$1 [L,QSA]

</IfModule>

providers/provider1 does not exist in the ProcessWire page tree, it comes from the old CMS.

Finally I tried http://modules.processwire.com/modules/process-redirects/ which works well, but I wanted to learn how to redirect with htaccess, I think is faster.

Link to comment
Share on other sites

The two rules should appear immediately after RewriteEngine On so that those redirects are the first things checked for, before any other rules are checked.

I'd only recommend using .htaccess if you have a few redirects and a small site with not many daily visitors that would hit the old links. As an alternative use the Redirects module, or my own Jumplinks module, which might save you some time as it does support wildcards. Running these modules on a small site won't affect performance at all.

Link to comment
Share on other sites

The two rules should appear immediately after RewriteEngine On so that those redirects are the first things checked for, before any other rules are checked.

Perfect! Now works! :)

I have around 90 redirects to do, and the site receives about 360 pageviews per day. The site produces revenue, so I'd like to not lose any speed. For this numbers( 90 and 360) do you think I should stick with .htaccess file  or should I use a module?

Thank you very much! 

  • Like 1
Link to comment
Share on other sites

Perfect! Now works! :)

I have around 90 redirects to do, and the site receives about 360 pageviews per day. The site produces revenue, so I'd like to not lose any speed. For this numbers( 90 and 360) do you think I should stick with .htaccess file  or should I use a module?

Thank you very much! 

For those amounts, I'd defintely recommend one of the two modules. The speed difference is hardly noticable. If you had a lot more page views and very little memory on your server (the chances of which are very slim these days), then I would recommend .htaccess so that the ProcessWire system does not need to boot up for every redirect.

Also remember that once you have the new links on your site, search engines start indexing them, and remembers that you have permanent redirects. So, over time, the redirects won't even occur.

Link to comment
Share on other sites

Thanks again, Mike!

Would be interesting to know - for everybody - what do you estimate to be the threshold (amounts of redirects+pageviews) of using modules vs .htaccess file.

Also I would appreciate very much your estimation about the time search engines remembers for good the permanent redirects (so it would be safe to remove them after e.g. 1 year)

Link to comment
Share on other sites

Thanks again, Mike!

Would be interesting to know - for everybody - what do you estimate to be the threshold (amounts of redirects+pageviews) of using modules vs .htaccess file.

Also I would appreciate very much your estimation about the time search engines remembers for good the permanent redirects (so it would be safe to remove them after e.g. 1 year)

Due to the fact that every server is different, the figure would be an average, which I don't know. Maybe someone else can shed some light on that.

I would recommend only removing redirects when it is determined that they are no longer being hit. Jumplinks provides this functionality - each jumplink has a hit counter and, when you hover over it, you are told when last the jumplinks was hit. That said, I prefer to just keep redirects up permanently. Others may prefer to do it differently.

Link to comment
Share on other sites

Ok good to know about the hit counter. I installed Jumplink - works very well and has more features - the perfect tool to migrate from other CMS!

Thank you for your contribution and for your help!!

-good ProcessWire community-  :)

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...