Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question htaccess rule to redirect to a script

    Hi Everyone

    I'm trying to write an .htaccess rule to redirect to a script, which further redirects somewhere else. However, I don't want the address url to change during the .htaccess part of the redirect.


    Example:
    test.mytest.com/page/test/hello
    this page should be hanlded by test.mytest.com/environment_test.php
    but test.mytest.com/page/test/hello still appears in browser.


    Thanks for reply in advance

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Not a thing to do with PHP. Moving to Apache configurations.

    If you issue a redirect, it will follow it. Use rewrite if you don't want to make the url appear to change. Not sure how you want to formulate the matching, with the example you have here a simple:
    Code:
    RewriteEngine On
    RewriteRule /page/test/hello$ environment_test.php
    Is sufficient.

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm working with Rahul on this...

    1) URL rewrite is what we want, thanks for clarifying.

    2) Let's say we want all pages, after the domain name to be handled by environment_test.php. How would you update your htaccess for that?

    Meaning, we want...

    test.mytest.com/page/test/hello
    test2.mytest.com/page/test/hello/1234
    test2.mytest2.com/different

    ...all to be handled by environment_test.php. The application will take it from there in terms of producing an output.

    3) Then, how would we throw in an exception? Say we have a file that if it is accessed in the URL, we want it to this to actually load the file they're requesting. For example...

    test.mytest.com/app/run.php

    Can we make it so anything in the /app/ folder will actually run if the file being requested (run.php) exists?

    4) Lastly, we will use this for dev/staging/production - can we insert a wildcard for the domains?


    Thanks!

  • #4
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    any help here?

  • #5
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    anyone?

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You can use RewriteCond to determine if the requested is a directory or a file. What would probably work is a:
    Code:
    RewriteCond %{REQUEST_FILENAME} !-f
    And proceed with your matching rules. That should only apply the rewrite rules so long as the requested file is not an actual file.

    For domains, you can also use the RewriteCond to match hosts. This would allow a one line swap when you change a domain.

    I hope that helps some, I'm not an apache wizard but I can typically stumble my way through.


  •  

    Posting Permissions

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