Quick mod_rewrtie quesyion

Discussion in 'Coding Help' started by ziycon, Feb 25, 2008.

  1. ziycon

    ziycon New Member

  2. ziycon

    ziycon New Member

    Using this now and im getting an internal 500 error!?!
    Code:
    RewriteRule ^([^/]*)$ /profile.php?name=$1 [L]
     
  3. CiaranR

    CiaranR Weeno Ltd + Skimlinks.com

    Code:
    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteRule ^([^/\.]+)/?$ profile.php?name=$1 [L]
    
    
    That should do it.
     
  4. ziycon

    ziycon New Member

  5. paul

    paul Ninja

  6. ziycon

    ziycon New Member

    I was using it but the code it gave me made the 500 error come up!
     
  7. paul

    paul Ninja

    500 error is an internal server error. When you have mod rewrite in place, you should still be able to see the URL for the non mod-rewrite'd page , right ? Have you tried this ? Maybe the error is in your script.
     
  8. ziycon

    ziycon New Member

    All i did was change the .htacess line to what i posted in the second post in this thread and it gave me a 500 internal error, once i removed it the site was fine!
     
  9. CiaranR

    CiaranR Weeno Ltd + Skimlinks.com

    Can you post your full .htaccess file there should be no problems with the code I said above.
     
  10. ziycon

    ziycon New Member

    Sorted it just this second, was missing one letter in the .htaccess file! Thanks for the help!
     
  11. CiaranR

    CiaranR Weeno Ltd + Skimlinks.com

    Thought it was something like that, hence the request. Glad you got it sorted :)
     
  12. davidbehan

    davidbehan New Member

    Do you still need a hand with this? I've done it recently on a site.
     
  13. ziycon

    ziycon New Member

  14. davidbehan

    davidbehan New Member

    You can add a condition to your rule like this:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/(forum)/.*$
    RewriteRule ^([a-z0-9/-]+)$ inner.asp?p=$1 [NC,L]

    First line checks that a file doesn't actually exist, second a directory doesn't exist, third the URL doesn't start with forum, and last line (if all conditions above are false) executes the rewrite. I suspect you just need to add the third line to your code in the same format as above.

    HTH

    Dave
     
  15. CiaranR

    CiaranR Weeno Ltd + Skimlinks.com

    3 ways to do it

    1. daves way :)
    2. add this to the top of you .htaccess
    Code:
    RewriteRule ^/?(forum)/$ forum/index.php [L]
    3. add a .htaccess file to the forum folder with "RewriteEngine off"

    Another helpful rule is

    Code:
    #
    # ONLY FOR TESTING REWRITE RULES!!!!!
    #
    RewriteLog "/tmp/rewrite.log"
    RewriteLogLevel 5
    NEVER use this rule on a live site only use it for testing, the log files would be HUGE
     
  16. davidbehan

    davidbehan New Member

    Not promoting my own here but 2 would redirect everything from mysite.com/forum/ to mysite.com/forum/index.php and ignore the rest of the rules. Although it would work, personally I'd prefer not to see index.php. With 3, you won't be able to use htaccess in that folder then and I presume that you will want that if it's set up like this forum for example (see url above). If I'm wrong with that analysis of that rewrite code, sorry - I've only been writing them for a couple of months now.

    Good to have a bit of lateral thinking of a solution though.

    Thanks for the log file code - that would have been handy recently when I was debuging what the hell htaccess was doing! :D

    Rgds, Dave
     
  17. ziycon

    ziycon New Member

    That worked a treat, thanks lads. One another note while i have you here, any suggestions why mod_rewrite wont work at home on my test machine?
     
  18. davidbehan

    davidbehan New Member

  19. ziycon

    ziycon New Member

  20. CiaranR

    CiaranR Weeno Ltd + Skimlinks.com

    Ziycon if you are running apache on xp there should not be a problem make sure mod rewrite is enabled in apache. I test using xampp on my xp machine and have no problem testing mod rewrite.

    David my first one (no.2) should work as expected and leave the url as mysite.com/forum/ the same as with any other rule it doesn't add index.php, not sure why you thought it would.

    The 3rd does have that obvious disadvantage but without knowing his forum setup it may the easiest way so its good to have it as an option, lateral thinking as you say.

    Saying that I think your solution is the best one and would be the recommended one by me too.
     

Share This Page