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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:34:14+00:00 2026-05-26T07:34:14+00:00

To start, I am a beginner with PHP and .htaccess. Here is my dilemma…

  • 0

To start, I am a beginner with PHP and .htaccess. Here is my dilemma…

I have built dynamic pages and used htaccess to rewrite the urls. There are 3 types of pages… Examples:

State: example.com/massachusetts-colleges.html

City: example.com/massachusetts-colleges/boston-ma-colleges.html

College: example.com/massachusetts-colleges/boston-ma-colleges/harvard.html

The problem is that pages are being requested (from old linking structure probably) that shouldn’t exist such as:

example.com/boston-ma-colleges.html

The state urls are stored in a locations table in the database (stateSlug = massachusetts-colleges). The city urls are also stored in the locations table in the database and the corresponding state slug is also stored with that city (citySlug = boston-ma-colleges and stateSlug = massachusetts-colleges). The Colleges are stored in a different table and use ID’s to correspond with the cities.

How can I use .htaccess to prevent any "OTHER" urls from being accessible (page displays template and no data), and show a 404 page (or redirect to home page)?

This is what my .htaccess file looks like now:

RewriteEngine on
RewriteRule ^([^/\.]+)\.html?$ php/statePage.php?stateSlug=$1 [L]
RewriteRule ^([^/\.]+)-colleges/([^/\.]+)\.html?$ php/cityPage.php?citySlug=$2&stateSlug=$1 [L]
RewriteRule ^([^/\.]+)-colleges/([^/\.]+)/([^/\.]+)\.html?$ php/collegePage.php?collegeSlug=$3&citySlug=$2&stateSlug=$1 [L]

Again, I am somewhat new to the htaccess and php languages. I would appreciate any help in this matter.

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-05-26T07:34:15+00:00Added an answer on May 26, 2026 at 7:34 am

    Try the following, but replace index.php with your 404 page:

    Order allow,deny
    Allow from all
    RewriteEngine On
    
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$l [L]
    

    This should redirect all file and directory requests that were not found to index.php or your choice of script file, a 404 page for example. Just remember to set the headers to a 404 response code.

    I got this from the CodeIgniter wiki page at http://codeigniter.com/wiki/mod_rewrite/

    Their wiki page was very helpful when I tried to solve a similar problem.

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

Sidebar

Related Questions

To start, I know there are two kinds of JSON serialization currently built into
I am beginner and wanna to learn few things before i start php dev/learning
A python/django beginner's question: I have a datetime object (drive_date), a time object (start_time)
Start with a series of MS Office extensions built in C++ as COM objects.
I am a beginner in PHP. How can I restrict user access to controller.php
I plan to start web app development. (Html, Css and Php) I want to
What's the ideal Python version for a beginner to start learning Python? I need
to start I consider myself in between beginner and intermediate when it comes to
i have a javascript code that requests a php page to provide it with
The thing is I have to create a 2D matrix in php where each

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.