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 8447161
In Process

The Archive Base Latest Questions

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

So I just started messing around with Apache’s rewrite module and would like to

  • 0

So I just started messing around with Apache’s rewrite module and would like to make sure I have this right because I’ve seen it done a few different ways. My example code is just an experiment for now but it might end up being the basic structure of a new project I’m working on.

Here is my .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_\-]+)/?$ index.php?id=$1 [L,NC]
</IfModule>

My index file:

<?php
include 'views/headerView.php';
switch(strtolower($_GET['id']))
{
    case "first": include 'views/firstPageView.php';
    break;
    case "second": include 'views/secondPageView.php';
    break;
    default: include 'views/homeView.php';
}
include 'views/footerView.php';
?>

And the default homeView template:

<p>This is the home page.</p>
<p>To the first page. <a href="first">First Page</a></p>
<p>To the second page. <a href="second">Second Page</a></p>

My main concern is only having the url “first” and “second” in the anchor tags on the template. The urls are used in the switch on the index file to determine which view to show. I’m doing it this way so when the user clicks a link, the word “first” or “second” would be used in the rewrite module’s back reference and would show up in the url as domain.com/first instead of domain.com/?id=first. So am I on the right track here or am I missing something? Any helpful advice would be appreciated, thank you.

  • 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-10T10:07:05+00:00Added an answer on June 10, 2026 at 10:07 am

    So am I on the right track here or am I missing something? Any helpful advice would be appreciated, thank you.

    You are on the right track. There’s nothing wrong with what you’re doing here. You’re going to have to, of course, tweak things but in general you’re on the right track. You may want to have something that generates the links for you, some kind of mapping or something. So the “first” and that mapped to “views/firstPageView.php”. You can then use that in your index.php to handle the routing as well as it to generate links. So if something like “first” gets changed to “something_else”, you won’t need to go to all the templates and change them by hand.

    Additionally, you have the mod_rewrite rule handle a possible trailing slash. There’s a lot of randomness that can pop up because of trailing slashes. Apache will 301 redirect a URL missing the trailing slash to one that includes the trailing slash when mod_dir thinks the request is for a directory. You may want to make all your links have a trailing slash to avoid this. Also, if you have a trailing slash, relative links like <a href="first">First Page</a> may stop working because the URI base is now /first/ instead of /.

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

Sidebar

Related Questions

I just started messing around with C#/.NET/mono and stuff, and I'm trying to make
I just started messing with generics and I want to make sure I got
I just started messing around with the lastfm API and I'm not sure why
I've just started messing around with php recently and I was testing my new
I just started learning about servers, and I am messing around with Google's App
I just started messing around with having my application store sessions in the database
I just started messing around with AJAX in an attempt to validate a form
I've been messing around with this for some time. I recently started using the
I've just started messing around with F# and am trying to do some basic
I've just started messing around with Windows Phone development, and I'm looking for some

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.