Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8479595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:04:26+00:00 2026-06-10T19:04:26+00:00

I am trying to create URLs in PHP and use the path ( $path

  • 0

I am trying to create URLs in PHP and use the path ($path) in if statements.

At work, we use ASP Classic and have some file(s) that allows us to do things like:

<%
 if path = "checkout" then

 <!--#include file="ViewCheckout.asp"-->

 elseif path = "billing" then

 <!--#include file="ViewBilling.asp"-->

 end if
%>

We can use the ‘ if path = “checkout” ‘ pretty much anywhere on our site. The curious thing is that ‘http://myworksite.com/checkout/‘ is the URL of the checkout page, yet there is no directory on our server called “checkout“… The above is just a couple of the list of ‘if path = “blah”‘ includes that appear in our ‘start.asp’ (The file that contains the base template of the pages).

I’ve seen files like ParseURL.asp and other files (at work) that somehow create these URLs and allow us to use them globally. I am trying to learn how this is done in PHP (At work, we run Windows Server, I have a Linux box).

What I am trying to do is create the following URLs for their respective pages:

  • http://mysite.com/browse/ – browse.php
  • http://mysite.com/contact/ – contact.php
  • http://mysite.com/top100/ – top100.php

And again, I would like to create these URLs WITHOUT creating directories for the paths.

I have read up on *http_build_url* and *parse_url*, but I am having a hard time determining the way to create URLs in the manner mentioned above.

The http_build_url tutorials I’ve found show this:

<?php
echo http_build_url("http://user@www.example.com/pub/index.php?a=b#files",
    array(
        "scheme" => "ftp",
        "host" => "ftp.example.com",
        "path" => "files/current/",
        "query" => "a=c"
    ),
    HTTP_URL_STRIP_AUTH | HTTP_URL_JOIN_PATH | HTTP_URL_JOIN_QUERY | HTTP_URL_STRIP_FRAGMENT
);
?>

The thing is, I can’t figure out if this just outputs ftp://ftp.example.com/pub/files/current/?a=b&a=c as text or if it is a way to create a valid URL… (This is obviously an FTP address…) – PHP.net

Note:
At work, we can also use the if path = “contact” to include certain snippets like this:

<%
 if path = "contact" or path = "chat" or path = "checkout" then

 <div id="communication-nav">
  <ul>
   <li>Some link 1</li>
   <li>Some link 2</li>
   <li>Some link 3</li>
  </ul>
 </div>

 end if
%>

If anyone can give me some pointers on how to re-create this using PHP, I would be very grateful!

Am I researching the right functions? Do I need to use some sort of URL Re-write function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:04:28+00:00Added an answer on June 10, 2026 at 7:04 pm

    After much research, I figured out how to do this the way I needed to… First, I inserted some code that made the index.php file “dynamic”. I placed this where the “content” of each page was going to be displayed…

    <?
        $p = $_GET['page'];
    
    $page = "pages/".$p.".php";
    
    if(file_exists($page))
        include($page);
    elseif($p=="")
        include 'pages/home.php';
    elseif($p=="about")
        include 'pages/about.php';
    elseif($p=="contact")
        include 'pages/contact.php';
    elseif($p=="disclaimer")
        include 'pages/disclaimer.php';
    else
        include '404.html';
    ?>
    

    What this does is include the appropriate “content” file that I want to show depending on what page someone is trying to view. I stored my different pages in the /pages/ directory of my site. You can change this to whatever you want to.

    Next, (if you are running an APACHE server and have the mod_rewrite module running (most hosting services and APACHE boxes have this module active) we want to open (or create if none exists in your site’s directory) the .htaccess file. This can be done with notepad or dreamweaver. Just name the file “.htaccess” and make sure you don’t save it as a “.txt”.

    The .htaccess file needs to contain the following in order to achieve what I needed…

    RewriteEngine on
    RewriteRule ^(.*)/$ index.php?page=$1
    

    The ^ marks the start of the string, the (.*) basically designates anything can be here, the / is the /about/ (there is more to this), and the $ marks the end of the string I believe.

    Note the space after $… After the space, you state what the URL currently is (which is what the block of code at the beginning of my answer generated)… In my case it was index.php?page=about. The $1 is not a PHP variable, it represents the value of the first variable which is about (or whatever the page you are viewing is).

    Now I highly recommend looking up “mod_rewrite” tutorials before dipping into this. It is new to me and pretty confusing. This video was helpful to me ( http://www.practicalecommerce.com/articles/394-Video-Tutorial-Eliminating-Dynamic-URLs-with-Mod-Rewrite ).

    Thanks everyone for the help here! As always, it’s greatly appreciated! 🙂

    Note Once I got this configured, my CSS was completely broken and none of my images showed up. I played around with the hrefs and got it dialed. Apparently these false “directories” impact hrefs as though they existed? Anyways, if you encounter this, don’t panic 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create tiny urls like this: site.com/abc123 goes to: site.com/index.php?token=abc123 but I
I am trying to create a url router in PHP, that works like django's.
I am trying to create a gridview and load some images from URLs to
I am trying to create a simple web crawler using PHP that is capable
I have a rewirte rule that rewrites my portfolio urls from portfolio.php?cat=cat-name&project=project-slug to /portfolio/cat/slug/
I am trying to create an android app which will show multiple web urls
I'm trying to figure out how to create personalized urls for double-byte languages. For
for some days now I have been trying to make a simple mod_rewrite rule
I am trying to create images hyperlinked to some URL's and hyperlinks donot seem
I am trying to create search engine friendly URLs with the following .htaccess and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.