Jump to content

redirect from one file


hakmir

Recommended Posts

is it possible that one php file will redirect all the requested pages like this:

 

for example when people type these addresses it will first go to redirect.php then depends on what they type after www.yoursite.com, it will redirect those pages.

 

www.yoursite.com/firstpage

www.yoursite.com/secondpage

www.yoursite.com/thirdpage

 

I know that for every request you can make a separate page but  I just want one page to redirect all. Thanks in advance

Link to comment
Share on other sites

this is accomplished with .htaccess files.  Read up on mod-rewrite.  But yes, you will eventually need a simple file like redirect.php with code something like:

 

<?php

if ( $_GET["url"] == 'blah' ) die( header( "Location: blah.php" ) );
if ( $_GET["url"] == 'blah2' ) die( header( "Location: blah2.php" ) );
//Etc...

?>

Link to comment
Share on other sites

this is accomplished with .htaccess files.  Read up on mod-rewrite.  But yes, you will eventually need a simple file like redirect.php with code something like:

 

<?php

if ( $_GET["url"] == 'blah' ) die( header( "Location: blah.php" ) );
if ( $_GET["url"] == 'blah2' ) die( header( "Location: blah2.php" ) );
//Etc...

?>

 

Your current pages are called using index.php with parameter of url i.e

http://www.example.com/index.php?url=category

and instead of this URL, you want a nice and easy to read URL like http://www.example.com/category

Solution - Put the following lines in your .htaccess file.

 

RewriteEngine on

RewriteRule ^([^/\.]+)/?$ /index.php?url=$1 [L]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.