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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2008
    Posts
    150
    Thanks
    24
    Thanked 0 Times in 0 Posts

    please help in htaccess redirect

    hello,
    i wanna redirect php file called file.php to path called /web/ in the same directory .

    so i was trying like that

    RewriteEngine on
    Options +FollowSymlinks
    RewriteRule ^file\.php$ /web/ [R=301,L]


    but it redirected me to my main site url web/ with ignoring the file.php directory and the its path too, i mean the file.php in url www.mysite.com/path1/path2/file.php , i uploaded the htaccess file in path2 folder

    but my rule redirected me to www.mysite.com/web/ not www.mysite.com/path1/path2/web/ !!!!!!


    so please for some reason i cant write the path in the rule, i mean i cant write like that
    RewriteRule ^file\.php$ path1/path2/web/ [R=301,L]

    it gonna works but i have reason that makes me not able to do it and i have to got direct rule without write path in the htacces file

    so please help me in that

    thanks

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    If you just want to redirect, you don't need a rewrite rule. You just need a redirect. And if it really is a php file, you don't even need to go into htaccess, you can just have php send a header(Location:balhblahblah) and redirect that way. Much simpler.

    If you don't like that method, Redirect and Alias would be easier than url rewriting.
    Are you a Help Vampire?

  • Users who have thanked tomws for this post:

    crazy.works (02-26-2009)

  • #3
    Regular Coder
    Join Date
    Jul 2008
    Posts
    150
    Thanks
    24
    Thanked 0 Times in 0 Posts
    well , thanks for the reply .

    about the php header , i know about it sure .
    but this htaccess will use in more than one host so , i have to set it , not in php

    so about the link that u just sent , iam thankful for it , but it doesnt work as i want

    i inserted that code in the htaccess file
    RedirectMatch (.*)file\.php$ /web/

    it redirected me to www.mysite.com/web/ with ignoring the path that the htaccess uploaded into

    so how can i make it redirect to /web/ in the same path that i uploaded the htaccess into, is there path query for the htaccess like [PHP_SELF] in the php ??? or what i have to do please

    thanks

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    is there path query for the htaccess like [PHP_SELF] in the php ???
    There are many things like REQUEST_URI and HTTP_HOST to fine tune your redirect rules.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Regular Coder
    Join Date
    Jul 2008
    Posts
    150
    Thanks
    24
    Thanked 0 Times in 0 Posts
    thanks i got it done with adding variable for the path
    RedirectMatch (.*)file\.php$ $1web/


  •  

    Posting Permissions

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