SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .htaccess and URL rewrite question

    Hi Guys,

    I'm trying to create some modrewrite rules where any directory within my demo directory, will be redirected to page.php.

    For example if I try to access, the following here's the outcome I expect:

    URL: http://www.mydomain.com/demo/about >>> http://www.mydomain.com/demo/page.php
    URL: http://www.mydomain.com/demo/contact >>> http://www.mydomain.com/demo/page.php

    Here's the code I currently have:
    Code:
    RewriteEngine on
    RewriteBase /demo
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /page.php [L]
    It doesn't work, any ideas whats wrong?

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

    It's really the same thing I've whined about for the last couple of years (about WP's mod_rewrite code) except that you are smart enough to have removed their <IfModule> wrapper.

    In particular, I don't like the use of RewriteBase as that affects your entire website (including your DocumentRoot). RewriteBase is designed to UNDO a mod_alias Redirect for mod_rewrite, not to change your DocumentRoot (as this would do).

    The first RewriteRule is unnecessary (provided the WP index.php file is used in the redirection - it's not) and the second RewriteRule MUST account for the lack of {REQUEST_URI} (http://www.example.com) with .? as the regex and /page.php is first checked in the server's root then your DocumentRoot (it's in the demo subdirectory). Finally, using something other than index.php as WP's handler file is likely to cause some major problems (within WP), too.

    How's that for "any ideas what(')s wrong?"

    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
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, thanks for your reply - but this isn't a Wordpress site. This is a custom designed application.

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

    "Same difference."

    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
  •