SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    586
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    rewrite rule to change php to html in subdirectory

    Hello Forums,

    I needed to change 2 files in a subdirectory from .php to .html so an android APP can access it. Here's what I have so far

    Code:
    RewriteEngine on
    RewriteRule ^event_upload.html?$  /mobile/event_upload.php [NC,L]
    event_upload.php is in an actual directory named mobile and I need to change it to event_upload.html

    Thanks,
    Don't Panic

  2. #2
    SitePoint Addict
    Join Date
    Oct 2009
    Location
    London, UK
    Posts
    382
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Why the question mark?

    try it without:
    Code:
    RewriteEngine on
    RewriteRule ^event_upload.html$  /mobile/event_upload.php [NC,L]

  3. #3
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    586
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello still does not work

    Here is my full htaccess at the root folder

    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^event_upload.html$  /mobile/event_upload.php [NC,L]
    </IfModule>
    Don't Panic

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

    The original? simply made the L optional.

    sd,

    OMG! That draws a standard rant:

    [standard rant #4]
    The definition of an idiot is someone who repeatedly does the same thing expecting a different result. Asking Apache to confirm the existence of ANY module with an <IfModule> ... </IfModule> wrapper is the same thing in the webmaster world. DON'T BE AN IDIOT! If you don't know whether a module is enabled, run the test ONCE then REMOVE the wrapper as it is EXTREMELY wasteful of Apache's resources (and should NEVER be allowed on a shared server).
    [/standard rant #4]

    Okay, take heed and please don't abuse your server with <IfModule> wrappers. They're only there to protect the canned app developers from whiners who have no clue what there server is capable of.

    Code:
    RewriteEngine on
    RewriteRule ^event_upload.html$  /mobile/event_upload.php [NC,L]
    From that I can see that you're on an Apache 2.x server (no leading / after the start anchor), that you don't know to escape the dot character in regex, that you're redirecting to mobile/event_uupload.php and have no clue what the No Case flag is used for. I would have used:

    Code:
    RewriteEngine on
    RewriteRule ^event_upload\.html$  /mobile/event_upload.php [R=301,L] 
    # for testing, the R=301 will display the redirection for you. In the operational world,
    # it would tell SE's to change their database to contain the new link, not the old.
    # IF you're satisfied that it works and want to hide the redirection, simply remove the R=301, from the flags.
    RewriteRule ^event_upload\.html$  mobile/event_upload.php [L]
    Question: Your statement "event_upload.php is in an actual directory named mobile and I need to change it to event_upload.html" is not represented in this code. What are you trying to do, change event_upload.html to event_upload.php but serve mobile/event_upload.php? If so, you'll need to simply change the file extension with an R=301 (so event.php is seen) then use another RewriteRule to add the mobile/ subdirectory with a simple Last flag.

    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.

    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

  5. #5
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    586
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks DK escaping periods worked ...and yah I removed the ifmodule wrapper ..silly me
    Don't Panic

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

    Great to know you've resolved your problem. Don't worry, not silly - I didn't know about the <IfModule> wrapper as a mod_rewrite newbie either!

    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
  •