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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:08:29+00:00 2026-06-15T15:08:29+00:00

I’ve been tasked with making the URLs for an old website pretty It’s a

  • 0

I’ve been tasked with making the URLs for an old website “pretty”

It’s a real estate website with a few dozen buildings and maybe 100ish total apartment listings.

Current urls are like: (i was able to remove .php extension easily with .htaccess)

example.com/about?building-id=65
example.com/about?apartment-id=35

It gets considerably more complicated than that, with some search pages, different listings views, a contact form page that gets sent a building or apt id to prefil the form with some info, etc…

But for this example…

Ideally the URLs should be

example.com/about/building-name/
example.com/about/building-name/apartment-name

The building name and apartment name are both values stored in the database, with the id#s as the primary keys.

After researching this issue a bit, I’ve determined a couple different approaches

1) Dynamically Generate the .htaccess file upon changes in admin

  • I think I can do this right?
  • It would explicitly rewrite just about every possible valid query string possibility ( up to couple hundred probably)
  • I imagine this will cause some performance issues, and is probably not best practice.
  • If its the easiest option, I’m ok with it being sloppy and bad practice as long as it works.

2) Create a controller and rewite all queries to index.php which would put together all the views from here.

  • This is a bit more out of my comfort zone, but probably considered the best practice?

The site is seriously old, and poorly put together (1000s of lines of custom (non OOP) php with lots of code duplication) For that matter, its really 2 different sites sharing the one database, and most of the code base (2nd was created some time ago with a copy-paste of original code base and has since grown apart)


My Question(s)

  • Are these viable options and did I miss any alternative?

  • Which approach should I take?

  • 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-15T15:08:29+00:00Added an answer on June 15, 2026 at 3:08 pm

    The actual generation of the .htaccess file wouldn’t be an issue. I mean, writing 500 or 1000 lines of text to a file isn’t such a big deal at all. However, the multitude of rules may actually very well give a performance hit, as the engine would check the requested URL against each for every HTTP request. It’s probably not a very big performance hit, but it seems wasteful to me. Note that Apache, AFAIK, does no optimization on .htaccess rewrite rules or redirects, i.e. it doesn’t build a big regex out of the small regexes, etc.

    Option 2, parsing the request in PHP, is actually less work, I think, especially with a huge non-OOP site.

    Consider a snippet like this:

    $uri = explode('/', $_SERVER['REQUEST_URI']);
    if($uri[0] == 'about') {
        $id_aray = lookup_building_and_apartment_by_name( $uri[1], $uri[2] );
        $_GET['building_id'] = $id_array['building'];
        $_GET['apartment_id'] = $id_array['apartment'];
        include('about.php');
    } 
    else if($uri[0] == 'something_else') {
        // something else.
    }
    else {
        // 404
    }
    

    Such a logic would serve perfectly well as a controller, and it isn’t such a big work.

    Alternarively, you could put a URI-parser snippet at the top of every entry point. Like, at the top of about.php:

    $uri = explode('/', $_SERVER['REQUEST_URI']);
    $id_aray = lookup_building_and_apartment_by_name( $uri[1], $uri[2] );
    $_GET['building_id'] = $id_array['building'];
    $_GET['apartment_id'] = $id_array['apartment'];
    

    This would enable you to work incrementally, one subpage at a time, and the old links would continue to work as well.


    Mostly for the record: there’s an option 3, you can use capture groups in mod_rewrite rules, like so:

    RewriteRule ^/about/([^/]+)/([^/]+)$ about.php?building_name=$1&apt_name=$2 [NC,L]
    RewriteRule ^/about/([^/]+)$ about.php?building_name=$1 [NC,L]
    

    (This can be done with a single rule, but it’s considerably easier to read & write like this.) This still requires you to have a php-based translation in about.php, but has the advantage that you can put these rules in your httpd.conf.

    There’s also an option 4: RewriteMap. It’s an awesome and powerful tool, and it may be just the thing for you, if you’re able to cope with the terseness of the Apache manual. Learning to use it would probably take a lot more time than using the PHP-based solution, but it’s a good thing to know, it’s an efficient solution, and it’s very elegant.

    You could easily generate a text-based mapping, then use the mapping in the RewriteRule, like so:

    RewriteMap building_map txt:/etc/apache2/buildings.txt
    RewriteRule ^/about/([^/]+)$ about.php?building-id=${building_map:$1|0} [NC,L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have been unable to fix a problem with Java Unicode and encoding. The
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I'm making a simple page using Google Maps API 3. My first. One marker
Let's say I'm outputting a post title and in our database, it's Hello Y’all

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.