need help with php redirection

by mbwani
11 replies
i want to redirect the link to some external link and i created the php file and uploaded it on the server .
php file looks like this
Code:
<?php
header('Location: http.........example.com' );
?>
i linked the url of file in the post so that when someone clicks on the link he will be redirected to example.com.
this code is not working as when i click on the link it is displaying post url/link url
and shows 404 error however when i check for link url only in browser it works fine.
i don't know why post url is coming infront of link url. please help ..
#php #redirection
  • Profile picture of the author vulcanscripts
    Do you have a .htaccess file that contains any mod_rewrite rules? I don't think your problem relates to your php code so it's likely to be a server side request conflict.
    Signature
    Live Track Mobile Spy - Android Spy Software
    Postcode Palâ„¢
    - Geo Datasets for GB, NI, CI and the Isle of Man
    {{ DiscussionBoard.errors[6737952].message }}
  • Profile picture of the author mbwani
    yes i have an .htaccess file and code for that is below :
    Code:
     
    
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    please check if it is OK.
    Signature
    Playmovie online | A right place to watch Full length movies online
    Watchmovies free | Watch Full length Hollywood Movies For Free.
    {{ DiscussionBoard.errors[6738096].message }}
  • Profile picture of the author RuffRage
    PHP is better. For debbugin's sake, remove the header etc and use a html meta redirect.
    {{ DiscussionBoard.errors[6738184].message }}
    • Profile picture of the author vulcanscripts
      I'm assuming that the php script you have created with the header redirect code is located in the same directory as your .htaccess? If so then there is definitely a URI parsing conflict. Your base directory for re-writing is "/". Based on your mod_rewrite rules every request to your base directory (relative from your domain) is being re-written through index.php. I would suggest either moving your redirect script out of the base directory or creating a new rule in your .htaccess file to exclude it from being re-written.

      Example exclusion rule:

      Code:
      RewriteRule ^/redirect.php$ - [L]
      Where "redirect.php" represents the file name of your redirect script.
      Signature
      Live Track Mobile Spy - Android Spy Software
      Postcode Palâ„¢
      - Geo Datasets for GB, NI, CI and the Isle of Man
      {{ DiscussionBoard.errors[6738189].message }}
      • Profile picture of the author mbwani
        Originally Posted by vulcanscripts View Post

        I'm assuming that the php script you have created with the header redirect code is located in the same directory as your .htaccess? If so then there is definitely a URI parsing conflict. Your base directory for re-writing is "/". Based on your mod_rewrite rules every request to your base directory (relative from your domain) is being re-written through index.php. I would suggest either moving your redirect script out of the base directory or creating a new rule in your .htaccess file to exclude it from being re-written.

        Example exclusion rule:

        Code:
        RewriteRule ^/redirect.php$ - [L]
        Where "redirect.php" represents the file name of your redirect script.
        i have created folder "link" in base directory and put the redirect php inside that folder.
        where to put above mentioned code in the .htaccess file either replace some code with the above code or add this as extra line in .htaccess.

        thanks for help.
        Signature
        Playmovie online | A right place to watch Full length movies online
        Watchmovies free | Watch Full length Hollywood Movies For Free.
        {{ DiscussionBoard.errors[6738969].message }}
        • Profile picture of the author vulcanscripts
          Your script should work fine in your seperate "links" directory that you created, but if you want it in the same directory as your re-write base then I would add the exclusion rule as your first rule in your .htaccess file, after the line specified with your re-write base.

          I.E.

          Code:
          # BEGIN WordPress
          <IfModule mod_rewrite.c>
          RewriteEngine On RewriteBase /
          RewriteRule ^/redirect.php$ - [L]
          RewriteRule ^index.php$ - [L]
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule . /index.php [L]
          </IfModule> 
          # END WordPress
          Signature
          Live Track Mobile Spy - Android Spy Software
          Postcode Palâ„¢
          - Geo Datasets for GB, NI, CI and the Isle of Man
          {{ DiscussionBoard.errors[6739039].message }}
    • Profile picture of the author vulcanscripts
      Originally Posted by RuffRage View Post

      PHP is better. For debbugin's sake, remove the header etc and use a html meta redirect.
      With regards to the OPs problem this will not help. His php script isn't even being parsed by the interpreter and is effectively being re-written on the uri request.
      Signature
      Live Track Mobile Spy - Android Spy Software
      Postcode Palâ„¢
      - Geo Datasets for GB, NI, CI and the Isle of Man
      {{ DiscussionBoard.errors[6738235].message }}
  • Profile picture of the author mbwani
    i tried both the methods ,
    firstly i put the redirect script in the "links" Directory i.e,
    domain.com/links/script.php when this url is alone entered it gets redirected to external url
    and when clicked from the post link the url becomes,
    domain.com/date/post/domain.com/links/script.php
    and ends with 404 error .
    after that i updated the .htaccess file and still the same thing happens.
    i cant understand what is happening ...
    Signature
    Playmovie online | A right place to watch Full length movies online
    Watchmovies free | Watch Full length Hollywood Movies For Free.
    {{ DiscussionBoard.errors[6739139].message }}
    • Profile picture of the author Jeff Hope
      If this is a Wordpress installation, why not use one of the many WP redirect plugins?

      Page Links To
      WP Redirection
      Pretty Links

      and many others.
      {{ DiscussionBoard.errors[6739307].message }}
    • Profile picture of the author vulcanscripts
      Originally Posted by mbwani View Post

      and when clicked from the post link the url becomes,
      domain.com/date/post/domain.com/links/script.php
      This sounds like WP itself modifying the link you are publishing. Probably because it's not being classed as an external link and is on the same domain as your WP installation. This will require modification of WP code and/or settings. I would take the advice of Jeff above and look into using a WP plugin as his advice would be much simpler than modifying the behaviour of WP.
      Signature
      Live Track Mobile Spy - Android Spy Software
      Postcode Palâ„¢
      - Geo Datasets for GB, NI, CI and the Isle of Man
      {{ DiscussionBoard.errors[6739576].message }}
  • Profile picture of the author mbwani
    thanks all for helping , i think now plugin is the only option for me.
    Signature
    Playmovie online | A right place to watch Full length movies online
    Watchmovies free | Watch Full length Hollywood Movies For Free.
    {{ DiscussionBoard.errors[6740188].message }}

Trending Topics