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
https://forums.phpfreaks.com/topic/134318-redirect-from-one-file/
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...

?>

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.