+ Reply to Thread
Results 1 to 3 of 3

Thread: URI rewrite ( replace backslash with forward slash )

  1. #1
    sasanka is offline x10Hosting Member sasanka is an unknown quantity at this point
    Join Date
    Apr 2010
    Posts
    3

    URI rewrite ( replace backslash with forward slash )

    I have a flash menu in my website which works good when using IE but not when using FireFox. Reason is Flash (SWF) file has resource path specified in the form \\xxx\\menudata.xml. IE replace the forward slashes before sending the request to the server but not FF. Unfortunately I do not have the source for the SWF so I cannot change it.

    Other option is to change it on the fly, therefore I am trying to use "rewrite" in .htaccess to replace "\\" with "/" as follows,

    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^(.*)\\(.*)$
    RewriteRule .* %1/%2 [R=301,NC,L]

    I have tested the above code in Ubuntu11.04/Apache2.2 and it works fine there but not here in X10Hosting.


    CPANEL ERROR MESSAGE as below
    File not found [/home/sasankav/public_html/includes\js\menudata.xml

    I am unable to figure out anything and have no clue about what could be wrong here, Please help and thanks in advance.

    Sasanka.

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: URI rewrite ( replace backslash with forward slash )

    Backslashes should be URI-escaped in URI paths, so you'll need to account for this in your rewrite condition:

    Code:
    RewriteCond %{REQUEST_URI} ^(.*)(\\|%5C)(.*)$
    RewriteRule .* %1/%3 [R=301,NC,L]
    However, using Apache to change backlashes to forward slashes is inefficient as it will only change one character per request, resulting in one extra requests per backslash in the URL path for each resource. Even though you don't have access to the source for the flash movie, you can try a hex editor, flash decompiler or SWF editor to change the resource. Failing that, pipe any URI paths through a script to generate the 301 redirect:

    Code:
    RewriteCond %{REQUEST_URI} (\\|%5C)
    RewriteRule (.*) fixslashes.php?uri=$1 [L]
    fixslashes.php:
    PHP Code:
    <?php
    /* The "uri" query param is unnecessary, but using it is less magical & mysterious */
    if (isset($_REQUEST['uri'])) {
        
    $path $_REQUEST['uri'];
    } else {
        
    $path $_SERVER['REQUEST_URI'];
    }
    $path preg_replace('/\\+|%5C/''/'$path);
    header('Location: ' $pathTrue302);
    A rewrite map would be useful here, but you can't define external rewriting programs in .htaccess.
    Last edited by misson; 10-21-2011 at 10:39 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    sasanka is offline x10Hosting Member sasanka is an unknown quantity at this point
    Join Date
    Apr 2010
    Posts
    3

    Re: URI rewrite ( replace backslash with forward slash )

    Thank you very much. It worked like a charm.

    -- Sasanka

+ Reply to Thread

Similar Threads

  1. PHP/RegExp: Escaping forward slash
    By tenx23 in forum Programming Help
    Replies: 2
    Last Post: 08-04-2011, 03:30 AM
  2. Can someone help me replace two files?
    By rcresume in forum Free Hosting
    Replies: 3
    Last Post: 02-28-2010, 04:59 PM
  3. Javascript Replace
    By seaside in forum Programming Help
    Replies: 16
    Last Post: 10-07-2009, 10:43 PM
  4. Can't replace images?
    By jmcgowan in forum Free Hosting
    Replies: 7
    Last Post: 07-12-2009, 11:04 AM
  5. php replace question
    By hyeclass in forum Scripts & 3rd Party Apps
    Replies: 1
    Last Post: 02-02-2006, 03:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers