SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Trick ReWrite

  1. #1
    SitePoint Addict Shaydez's Avatar
    Join Date
    Jul 2006
    Location
    Boca Raton, Florida
    Posts
    356
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Trick ReWrite

    I'm trying to achieve something a bit tricky. not sure if its possible.

    what i want to do is

    domain.com/any_page_name.html (this will call page.php)
    domain.com/florida-miami/helmets/red-blue/2 (this will call list.php, however the trailing needs to be unlimited. I have a URI Mapper handling this.

    I currently have follow but its kind of backwards.

    RewriteRule ^/?(.*).html$ list.php?pg=$1
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php

    Result is
    domain.com/page (gets page.php) only because i remove the php extension when i add .html it goes to list.
    domain.com/state-city/anything/ works

    Basically i want it to be like if its list.php then use the rewrite everything is else should be .html or run as a regular page.

    cuz if i tried to run a file in another directory it think i'm still using list.php

    thanks
    Sr. Website Developer and Internet Marketing
    www.CarlosJa.com Note: If anyone
    needs to get ahold of me please feel free to email me through
    my site. Apparently i missed quite a few private messages.

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Shay,

    Sorry to burst your bubble but it's not tricky at all. Your code has problems (besides not using the [code] ... [/code] wrapper) ...

    Quote Originally Posted by Shaydez View Post
    what i want to do is

    domain.com/any_page_name.html (this will call page.php)
    domain.com/florida-miami/helmets/red-blue/2 (this will call list.php, however the trailing needs to be unlimited. I have a URI Mapper handling this.
    Code:
    # MISSING
    RewriteEngine on
    
    # matches xyhtml, i.e., the dot character needs to be escaped to match ONLY the dot character
    # ^/? is only required if you don't know whether your on an Apache 1 or Apache 2 server. 
    # IMHO, find out and either use ^/ for Apache 1.x or ^ for Apache 2.x
    # Since I don't believe there are any Apache 1.x servers out there any more ...
    RewriteRule ^(.*)\.html$ list.php?pg=$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php [L]
    # PLEASE learn to use mod_rewrite's flags
    Quote Originally Posted by Shay
    Result is
    domain.com/page (gets page.php) only because i remove the php extension when i add .html it goes to list.
    domain.com/state-city/anything/ works

    Basically i want it to be like if its list.php then use the rewrite everything is else should be .html or run as a regular page.

    cuz if i tried to run a file in another directory it think i'm still using list.php

    thanks
    Sorry, the English got so twisted there that I'm not sure what you're asking. It seems to be that you only want list.html to be redirected to the php script, not other .html pages. If that's the case, WHY did you use the dreaded EVERYTHING (or NOTHING) atom to specify ... well, EVERYTHING (or NOTHING) instead of ... what?

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    No Edit available? :P

    Shay,

    Please note that, if you change the order of the RewriteRule (block) statements and the .html file(s) do not exist, they'll be redirected to index.php and NEVER to list.php.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •