SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    The usual mod_rewrite woes :p

    Well this worked fine on my localhost but when I ported it over to my clients server some parts don't work:

    #allow from all

    Options -Indexes +FollowSymLinks +Multiviews

    # Turn Rewrite Engine on
    RewriteEngine On

    ## rewrite news sections ##
    RewriteRule ^news/?$ article.php?action=view [L]
    #RewriteRule ^news/recent/?$ article.php?action=view [L]
    RewriteRule ^news/([0-9]+)/?$ article.php?action=read&id=$1 [L]
    RewriteRule ^news/submit article.php?action=submit [L]
    RewriteRule ^news/submitted article.php?action=submitted [L]
    RewriteRule ^news/archive/?$ articles_archive.php?action=archive [L]
    RewriteRule ^news/archive/([0-9]+)/?$ articles_archive.php?action=archive&pagenumber=$1 [L]

    ## Rewrite polls #####
    RewriteRule ^polls/archive/([0-9]+)/?$ polls.php?action=results&id=$1 [L]

    ## Rewrite gallery ##
    RewriteRule ^gallery/submit/?$ gallery.php?action=submit [L]
    RewriteRule ^gallery/?$ gallery.php?action=archive&pagenumber=1 [L]
    RewriteRule ^gallery/([0-9]+)/?$ gallery.php?action=archive&pagenumber=$1 [L]
    RewriteRule ^gallery/?$ gallery.php?action=archive [L]
    RewriteRule ^gallery/view/([0-9]+)/?$ gallery.php?action=view&id=$1 [L]

    ## Rewrite ecards ###
    RewriteRule ^ecards/([0-9]+)/?$ ecard.php?action=view&pagenumber=$1 [L]
    RewriteRule ^ecards ecard.php?action=view

    ## Rewrite events ###
    RewriteRule ^events/([0-9]+)/?$ events.php?action=view&pagenumber=$1 [L]
    RewriteRule ^events/?$ events.php?action=view [L]
    RewriteRule ^events/view/([0-9]+)/?$ events.php?action=details&id=$1 [L]

    ## Rewrite prizes ###
    RewriteRule ^prizes/([0-9]+)/?$ prizes.php?action=view&pagenumber=$1 [L]
    RewriteRule ^prizes/?$ prizes.php?action=view [L]
    RewriteRule ^prizes/view/([0-9]+)/?$ prizes.php?action=details&id=$1 [L]
    RewriteRule ^prizes/enter/([0-9]+)/?$ prizes.php?action=enter&id=$1 [L]

    ## Rewrite links ##
    #RewriteRule ^links/?$ links.php?action=view&level=1 [L]
    RewriteRule ^links/$1/([0-9]+)/?$ links.php?action=view&level=2&catid=$1&pagenumber=$1 [L]
    #RewriteRule ^links/enter/([0-9]+)/?$ prizes.php?action=enter&id=$1 [L]
    RewriteRule ^links/?$ links.php?action=view&level=1 [L]
    I mean there's that many things that don't work that I'd spend 20minutes writing down what each individual part doesn't work. But i'm sure to someone who knows their mod_rewrite can sort this out for me in minutes

    Thanks in Advance
    - Dean Clatworthy

  2. #2
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dean,
    without knowing what parts didn't work,
    I can see that:

    (a)
    >> ## rewrite news sections ##
    >> RewriteRule ^news/?$ article.php?action=view [L]
    >> RewriteRule ^news/([0-9]+)/?$ article.php?action=read&id=$1 [L]
    >> RewriteRule ^news/submit article.php?action=submit [L]
    >> RewriteRule ^news/submitted article.php?action=submitted [L]
    >> RewriteRule ^news/archive/?$ articles_archive.php?action=archive [L]
    >> RewriteRule ^news/archive/([0-9]+)/?$ articles_archive.php?action=archive&pagenumber=$1 [L]

    should be (in bold the rules I changed)
    RewriteRule ^news/?$ article.php?action=view [L]
    RewriteRule ^news/([0-9]+)/?$ article.php?action=read&id=$1 [L]
    RewriteRule ^news/submit/?$ article.php?action=submit [L]
    RewriteRule ^news/submitted/?$ article.php?action=submitted [L]

    RewriteRule ^news/archive/?$ articles_archive.php?action=archive [L]
    RewriteRule ^news/archive/([0-9]+)/?$ articles_archive.php?action=archive&pagenumber=$1 [L]

    Reason:
    I think that the link news/submitted never worked, the reason is that your rule
    ^news/submit
    matched news/submit and news/submitted

    (b)
    >> ## Rewrite gallery ##
    >> RewriteRule ^gallery/submit/?$ gallery.php?action=submit [L]
    >> RewriteRule ^gallery/?$ gallery.php?action=archive&pagenumber=1 [L]
    >> RewriteRule ^gallery/([0-9]+)/?$ gallery.php?action=archive&pagenumber=$1 [L]
    >> RewriteRule ^gallery/?$ gallery.php?action=archive [L]
    >> RewriteRule ^gallery/view/([0-9]+)/?$ gallery.php?action=view&id=$1 [L]
    The lines I marked in bold are in conflict... you may change them.

    (c)
    > ## Rewrite ecards ###
    > RewriteRule ^ecards/([0-9]+)/?$ ecard.php?action=view&pagenumber=$1 [L]
    > RewriteRule ^ecards ecard.php?action=view

    should be
    ## Rewrite ecards ###
    RewriteRule ^ecards/([0-9]+)/?$ ecard.php?action=view&pagenumber=$1 [L]
    RewriteRule ^ecards/?$ ecard.php?action=view [L]

    Reason:
    RewriteRule ^ecards will match ecard.php too...

    (d)
    >> ## Rewrite links ##
    >> RewriteRule ^links/$1/([0-9]+)/?$ links.php?action=view&level=2&catid=$1&pagenumber=$1 [L]
    >> RewriteRule ^links/?$ links.php?action=view&level=1 [L]

    Your first rule is not fine, it should be:
    RewriteRule ^links/([^/]+)/([0-9]+)/?$ links.php?action=view&level=2&catid=$1&pagenumber=$2 [L]
    RewriteRule ^links/?$ links.php?action=view&level=1 [L]


    ----
    puff pant,
    I think I've finished



    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  3. #3
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pippo you kick *** amigo !

    But not all is fixed Here's a rundown of what happens. When I go to mysite.com/dev/gallery it just shows a blank page.

    When I go to mysite.com/dev/links it shows a blank page also.

    When I go to mysite.com/dev/events it loads fine but when I proced to go to a mysite.com/dev/events/1 for example it'll just reload the same page as was loaded before for mysite.com/dev/events

    When I go to mysite.com/dev/prizes it loads fine but when I go to mysite.com/dev/prizes/1 it loads the same as mysite.com/dev/prizes

    Well that minimizes it somewhat eh

    Code at the moment:

    Options -Indexes +FollowSymLinks +Multiviews

    # Turn Rewrite Engine on
    RewriteEngine On

    ## rewrite news sections ##
    RewriteRule ^news/?$ article.php?action=view [L]
    #RewriteRule ^news/recent/?$ article.php?action=view [L]
    RewriteRule ^news/([0-9]+)/?$ article.php?action=read&id=$1 [L]
    #RewriteRule ^news/submit article.php?action=submit [L]
    #RewriteRule ^news/submitted article.php?action=submitted [L]
    ## new
    RewriteRule ^news/submit/?$ article.php?action=submit [L]
    RewriteRule ^news/submitted/?$ article.php?action=submitted [L]
    ## /end new
    RewriteRule ^news/archive/?$ articles_archive.php?action=archive [L]
    RewriteRule ^news/archive/([0-9]+)/?$ articles_archive.php?action=archive&pagenumber=$1 [L]

    ## Rewrite polls #####
    RewriteRule ^polls/archive/([0-9]+)/?$ polls.php?action=results&id=$1 [L]

    ####### Rewrite gallery ##
    #RewriteRule ^gallery/submit/?$ gallery.php?action=submit [L]
    #RewriteRule ^gallery/?$ gallery.php?action=archive&pagenumber=1 [L]
    #RewriteRule ^gallery/([0-9]+)/?$ gallery.php?action=archive&pagenumber=$1 [L]
    #RewriteRule ^gallery/?$ gallery.php?action=archive [L]
    #RewriteRule ^gallery/view/([0-9]+)/?$ gallery.php?action=view&id=$1 [L]
    RewriteRule ^gallery/submit/?$ gallery.php?action=submit [L]
    RewriteRule ^gallery/([0-9]+)/?$ gallery.php?action=archive&pagenumber=$1 [L]
    RewriteRule ^gallery/?$ gallery.php?action=archive [L]
    RewriteRule ^gallery/view/([0-9]+)/?$ gallery.php?action=view&id=$1 [L]

    ## Rewrite ecards ###
    RewriteRule ^ecards/([0-9]+)/?$ ecard.php?action=view&pagenumber=$1 [L]
    RewriteRule ^ecards/?$ ecard.php?action=view [L]

    ## Rewrite events ###
    RewriteRule ^events/([0-9]+)/?$ events.php?action=view&pagenumber=$1 [L]
    RewriteRule ^events/?$ events.php?action=view [L]
    RewriteRule ^events/view/([0-9]+)/?$ events.php?action=details&id=$1 [L]

    ## Rewrite prizes ###
    RewriteRule ^prizes/([0-9]+)/?$ prizes.php?action=view&pagenumber=$1 [L]
    RewriteRule ^prizes/?$ prizes.php?action=view [L]
    RewriteRule ^prizes/view/([0-9]+)/?$ prizes.php?action=details&id=$1 [L]
    RewriteRule ^prizes/enter/([0-9]+)/?$ prizes.php?action=enter&id=$1 [L]

    ## Rewrite links ##
    #RewriteRule ^links/?$ links.php?action=view&level=1 [L]
    #RewriteRule ^links/$1/([0-9]+)/?$ links.php?action=view&level=2&catid=$1&pagenumber=$1 [L]
    RewriteRule ^links/([^/]+)/([0-9]+)/?$ links.php?action=view&level=2&catid=$1&pagenumber=$2 [L]
    #RewriteRule ^links/enter/([0-9]+)/?$ prizes.php?action=enter&id=$1 [L]
    RewriteRule ^links/?$ links.php?action=view&level=1 [L]

  4. #4
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:


    I'm at home actually and I have some problems because I'm trying to use freebsd+xfce4 etc etc

    Try to remove the MultiViews option then:
    ( why do you need it ? )

    Options -Indexes +FollowSymLinks -Multiviews

    I didn't remember if Multiviews takes precedence over mod_rewrite, but the aim of Multiviews is to call /dev/links.php when you ask fro /dev/links (ie not extension)



    p.s.
    I have the suspect I won't be online too muc this evening...
    tomorrow morning I'll be...
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  5. #5
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well i'm about to run and catch the england soccer game so i'll be online tomorrow evening GMT Will give it a try and post feedback here tomorrow night

  6. #6
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok well pippo as ever you are a living genius - that little MutliViews tweak fixed it !

  7. #7
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok im back again - instead of making a new thread I thought i'd regurgitate this one

    Real simple question now.

    I want to to rewrite mysite.com/portfolio.php => mysite.com/portfolio so basically stripping the php extension off all PHP files. I uses Options +MultiViews at the top of my .htaccess file and that worked fine apart from I couldn't access any directories within the directory my .htaccess file was in. I'm sure there must be a one liner to solve this issue


Bookmarks

Posting Permissions

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