Development .htaccess Redirect Madness

Discussion in 'Software' started by Dizman, 25 Jul 2007.

  1. Dizman

    Dizman What's a Dremel?

    Joined:
    6 Jul 2006
    Posts:
    218
    Likes Received:
    0
    I have just rewritten a single page for work using some php. I want to redirect the old .html page to the new .php page. Simple, huh? The problem is that the university's system uses GET to wrap their template around every page. In this case, the old page is http://www.uvm.edu/irb/?Page=m1_forms.html&SM=humanmenu1.html and I just want to change the "m1_forms.html" to "m1_forms.php." It seems like it should be a relatively easy task, but I just can't figure it out. Any takers?
     
  2. trigger

    trigger Procrastinator

    Joined:
    22 Mar 2004
    Posts:
    1,106
    Likes Received:
    37
    Can you change the meta tags? If so you could just do it the old way with:

    Code:
    <meta http-equiv="Refresh" content="0; url=m1_forms.php />
     
  3. Fophillips

    Fophillips What's a Dremel?

    Joined:
    9 Oct 2006
    Posts:
    948
    Likes Received:
    1
    Last edited: 25 Jul 2007
  4. Dizman

    Dizman What's a Dremel?

    Joined:
    6 Jul 2006
    Posts:
    218
    Likes Received:
    0
    Fophillips, that seems like it should work, and makes perfect sense to me, but it just doesn't do anything. But I was playing around with it, and I can't get even a very simple one to work:

    Code:
    Redirect 301 /m1_forms.html http://www.uvm.edu/irb/m1_forms.php
    I've used ever combination of syntax changes and file paths that I can think of. Is it possible that the server has just turned off redirects?

    **Ninja Edit**

    I tried it on my own server and the simple one I posted above works, but the one you posted before doesn't. I'm getting the feeling it's the server config, at least partially...
     
    Last edited: 26 Jul 2007
  5. Jamie

    Jamie ex-Bit-Tech code junkie

    Joined:
    12 Mar 2001
    Posts:
    8,180
    Likes Received:
    54
    You may need to allow overrides if it isn't working.
     
  6. Dizman

    Dizman What's a Dremel?

    Joined:
    6 Jul 2006
    Posts:
    218
    Likes Received:
    0
    From what I can tell, "Allow Override" is a sitewide preference set in httpd.conf (correct me if I'm wrong). We are just a small part of a large institution, and there's no way the main web team will change it just for us. I'll try if it's the only way, but that brings me to my next point: I got mod_rewrite to work, at least without the GET part. This:

    Code:
    RewriteEngine on
    RewriteRule ^\m1_forms.html$ m1_forms.php
    works perfectly. But I can't figure out how to put in the GET part.
     
  7. Jamie

    Jamie ex-Bit-Tech code junkie

    Joined:
    12 Mar 2001
    Posts:
    8,180
    Likes Received:
    54
    You can put it in the htaccess as far as I am aware.

    Something along these lines?

    Code:
    RewriteEngine on
    RewriteRule ^\m1_forms.html(?something=(.*))?$ m1_forms.php?something=$2
     
  8. Dizman

    Dizman What's a Dremel?

    Joined:
    6 Jul 2006
    Posts:
    218
    Likes Received:
    0
    If "AllowOverride All" tells Apache to look for .htaccess files, and it is not set currently, how is Apache going to read the .htaccess file to see that it is supposed to read .htaccess files? Also, how much wood could a woodchuck chuck if a woodchuck could chuck wood?

    And as far as the GET line goes, I just need it to match this particular file. I was thinking that this would work:

    Code:
    RewriteRule ^\?Page=m1_forms.html$ /irb/?Page=m1_forms.php [R,L]
    But it doesn't.
     
  9. Fophillips

    Fophillips What's a Dremel?

    Joined:
    9 Oct 2006
    Posts:
    948
    Likes Received:
    1
    Try removing the $
     
  10. Dizman

    Dizman What's a Dremel?

    Joined:
    6 Jul 2006
    Posts:
    218
    Likes Received:
    0
    No such luck. But
    Code:
    RewriteRule ^m1_forms.html$ /irb/?Page=m1_forms.php [R,L]
    works just the same with or without it.
     
  11. Fophillips

    Fophillips What's a Dremel?

    Joined:
    9 Oct 2006
    Posts:
    948
    Likes Received:
    1
    Yes, but $ signifies the end of a URL. So ^m1_forms.html would match m1_forms.htmlkhdsiabibngonjoabnhbghablnjnajklngkjl
     
    Last edited: 27 Jul 2007
  12. Dizman

    Dizman What's a Dremel?

    Joined:
    6 Jul 2006
    Posts:
    218
    Likes Received:
    0
    Ah, that makes sense. I assumed there was some significance, and there it is. But the ?Page= part is still screwing it up for some reason.

    Btw, thanks for helping so far guys. I've learned quite a bit about this whole htaccess thing, even if it's driving me a bit insane.
     
  13. Fophillips

    Fophillips What's a Dremel?

    Joined:
    9 Oct 2006
    Posts:
    948
    Likes Received:
    1
    Can't you get your uni to stop using GET to access pages?
     
  14. Dizman

    Dizman What's a Dremel?

    Joined:
    6 Jul 2006
    Posts:
    218
    Likes Received:
    0
    The pages technically work fine without the GET bs, it just doesn't wrap the template around them. Also, they actually are working on a total redesign using a cms, but it's still a ways out. It certainly won't be done before my summer job is...

    It's a good thing that people won't be creating their own html files, though. You should see the amount of dreamweaver-crap that I needed to wade through.
     
  15. Dizman

    Dizman What's a Dremel?

    Joined:
    6 Jul 2006
    Posts:
    218
    Likes Received:
    0
    Allright, this has officially stopped making sense to me. Nothing will match the ? in a url. This should match:
    Code:
    RewriteRule ^.+m1_forms.html /irb/?Page=m1_forms.php [R,L]
    But it doesn't match http://www.uvm.edu/irb/?Page=m1_forms.html. If I take the question mark out (http://www.uvm.edu/irb/Page=m1_forms.html), it matches, and if I put in anything in its stead, it matches, but the question mark keeps it from matching.
     
  16. simon w

    simon w What's a Dremel?

    Joined:
    3 Nov 2003
    Posts:
    1,302
    Likes Received:
    0
    ? is a special character in regexs, it means 'zero or one' (in the same way + means 'one or more'). Try escaping it with a backslash,

    Code:
    RewriteRule ^.+m1_forms.html /irb/\?Page=m1_forms.php [R,L]
     
  17. Fophillips

    Fophillips What's a Dremel?

    Joined:
    9 Oct 2006
    Posts:
    948
    Likes Received:
    1
    Is the second part regex?
     
  18. simon w

    simon w What's a Dremel?

    Joined:
    3 Nov 2003
    Posts:
    1,302
    Likes Received:
    0
    After reading the question properly, probably not :D
     
  19. Dizman

    Dizman What's a Dremel?

    Joined:
    6 Jul 2006
    Posts:
    218
    Likes Received:
    0
    Yeah, I've tried escaping the question mark in the first part (the only regex part, as you've determined). I've tried using .+ which doesn't work either. Basically I can't find anything in regex that will match a question mark.
     
  20. Dizman

    Dizman What's a Dremel?

    Joined:
    6 Jul 2006
    Posts:
    218
    Likes Received:
    0
    Gah, I give up. Meta refresh, here I come...
     

Share This Page