Jump to content

Mod-Rewrite


Ne.OnZ

Recommended Posts

I started this discussion elsewhere, but it turned into something else. So, I'll ask the question I asked with Haku's quote:

 

f one page's content is www.yoursite.com/index.php?content=main, and another page's content is www.yoursite.com/index.php?content=about_us, then you set up the mod rewrite so that when you access:

 

www.yoursite.com/main

 

it shows the user the content of www.yoursite.com/index.php?content=main, and when you access

 

www.yoursite.com/about_us

 

it shows the user the content of www.yoursite.com/index.php?content=about_us. In this way, search engines will index the pages as entirely separate pages, even though they are actually both contained within index.php

 

How would I go about doing this? I'm so lost  :o!

 

Thank You.

Link to comment
https://forums.phpfreaks.com/topic/104035-mod-rewrite/
Share on other sites

<?php 
$page = $_GET["page"];
if (!$page) {
include "/home.php";
}

else if($page=="main")                { include "/main.php"; }

else if($page=="about_us")                { include "/about_us.php"; }

else { echo "<b><h1>404 Error</h1></b>"; } 
?>

 

Let me break it down for you.

include "/home.php";

means that the default home page is home.php so when you type www.website.com/index.php, home.php is the content.

 

else if($page=="main")                { include "/main.php"; }

means that if the page is index.php?page=main that the content will be included from main.php

Link to comment
https://forums.phpfreaks.com/topic/104035-mod-rewrite/#findComment-532568
Share on other sites

Put this in a .htaccess in the correct directory:

 

<IfModule mod_rewrite.c>

RewriteEngine On

</IfModule>

RewriteRule ^([a-zA-Z0-9]+)$ index.php?content=$1

RewriteRule ^([a-zA-Z0-9]+)/$ index.php?content=$1

 

It'll take ANY request that has no extension and is just letters and numbers and send it off to the index.php?content= thing.

Link to comment
https://forums.phpfreaks.com/topic/104035-mod-rewrite/#findComment-532784
Share on other sites

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.