Very Urgent...help required for redirecting to new URL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SmartPHP
    New Member
    • Jul 2007
    • 22

    Very Urgent...help required for redirecting to new URL

    I'm trying to build a site using PHP and apache.
    I have menu as my main navigation and tree on the left pane as secondary navigation for moving to different pages.
    i'm also using .htaccess file for redirection.

    on click of the tree items i pass URL of the form {menucategory}/{pageid.html} and the rewriterule in my .htaccess file is:

    RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)\.html$ index.php?categ ory=$1&pageid=$ 2 [L,QSA]

    now what's happennng is when i click any tree item first time it appends the URl with the base url like

    hhtp://localhost/mysite/home/homepage.html -- i'm sending url home/homepage.html.

    now when i click on some other tree item like home/login it is appending this url after the ../home/ instead of ../mysite/ like

    http://localhost/mysite/home/home/login

    can anyone tell me why it's happening like that...
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Originally posted by SmartPHP
    I'm trying to build a site using PHP and apache.
    I have menu as my main navigation and tree on the left pane as secondary navigation for moving to different pages.
    i'm also using .htaccess file for redirection.

    on click of the tree items i pass URL of the form {menucategory}/{pageid.html} and the rewriterule in my .htaccess file is:

    RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)\.html$ index.php?categ ory=$1&pageid=$ 2 [L,QSA]

    now what's happennng is when i click any tree item first time it appends the URl with the base url like

    hhtp://localhost/mysite/home/homepage.html -- i'm sending url home/homepage.html.

    now when i click on some other tree item like home/login it is appending this url after the ../home/ instead of ../mysite/ like

    http://localhost/mysite/home/home/login

    can anyone tell me why it's happening like that...
    Sounds like your links are using relative URLs. Try putting the full URL in for an easy way around this problem.

    Comment

    • SmartPHP
      New Member
      • Jul 2007
      • 22

      #3
      Originally posted by Motoma
      Sounds like your links are using relative URLs. Try putting the full URL in for an easy way around this problem.

      In that way how can i hide my actual directory index from the user???

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by SmartPHP
        In that way how can i hide my actual directory index from the user???
        I'm not exactly sure what you mean. Could you elaborate on what you are asking?

        Comment

        • SmartPHP
          New Member
          • Jul 2007
          • 22

          #5
          Originally posted by Motoma
          I'm not exactly sure what you mean. Could you elaborate on what you are asking?
          I mean to say i want the URL to be visible as http://servername/mysitename/au/users instead of http://servername/mysitename/activeusers/usersloggedin.p hp

          how can achieve this...b'coz when i tried to pass the full URL it was displaying the actual directory path not the canonical URL.

          Comment

          • Motoma
            Recognized Expert Specialist
            • Jan 2007
            • 3236

            #6
            Originally posted by SmartPHP
            I mean to say i want the URL to be visible as http://servername/mysitename/au/users instead of http://servername/mysitename/activeusers/usersloggedin.p hp

            how can achieve this...b'coz when i tried to pass the full URL it was displaying the actual directory path not the canonical URL.
            As I understand the problem, you have a rewrite rule (or many) set up, and you want people who type in the .php address to get redirected to the rewritten address.

            In this case you should use the HTTP 301 status with a header call and redirect to the proper address. The way I typically do this is by creating an include php file that handles all redirect cases. There are likely more elegant ways of doing this.

            Comment

            • SmartPHP
              New Member
              • Jul 2007
              • 22

              #7
              Originally posted by Motoma
              As I understand the problem, you have a rewrite rule (or many) set up, and you want people who type in the .php address to get redirected to the rewritten address.

              In this case you should use the HTTP 301 status with a header call and redirect to the proper address. The way I typically do this is by creating an include php file that handles all redirect cases. There are likely more elegant ways of doing this.

              You are right...i have few rewrite rule set up.
              can you provide me some example of the way you were telling i.e. creating an include php file that handles all redirect.

              Comment

              • Motoma
                Recognized Expert Specialist
                • Jan 2007
                • 3236

                #8
                Originally posted by SmartPHP
                You are right...i have few rewrite rule set up.
                can you provide me some example of the way you were telling i.e. creating an include php file that handles all redirect.
                Here is one that I use on my own website:

                [code=php]
                <?php

                if($_SERVER['HTTP_HOST'] != 'motomastyle.co m')
                {
                header('HTTP/1.1 301 Moved Permanently');
                header("Locatio n: http://motomastyle.com ".$_SERVER['REQUEST_URI']);
                exit();
                }

                ?>
                [/code]

                That one sends a 301 Moved Permanently response to any search engines that try using www to access my website. It also immediately redirects any user that happened to type www in the address.

                In your case, you would probably want to use REQUEST_URI as opposed to HTTP_HOST. Take a look at the PHP.net list of Predefined Variables

                Comment

                • SmartPHP
                  New Member
                  • Jul 2007
                  • 22

                  #9
                  Originally posted by Motoma
                  Here is one that I use on my own website:

                  [code=php]
                  <?php

                  if($_SERVER['HTTP_HOST'] != 'motomastyle.co m')
                  {
                  header('HTTP/1.1 301 Moved Permanently');
                  header("Locatio n: http://motomastyle.com ".$_SERVER['REQUEST_URI']);
                  exit();
                  }

                  ?>
                  [/code]

                  That one sends a 301 Moved Permanently response to any search engines that try using www to access my website. It also immediately redirects any user that happened to type www in the address.

                  In your case, you would probably want to use REQUEST_URI as opposed to HTTP_HOST. Take a look at the PHP.net list of Predefined Variables
                  I tried to understand how i can use 301 redirect in my case but i could not...if possible pls tell me how can i use it for my website....in my website i'm facing problem while clicking a link and loading another page.

                  Comment

                  Working...