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

  • Home
  • SEARCH
  • 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 9184873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:09:29+00:00 2026-06-17T19:09:29+00:00

I have my website with a sub-directory: http://www.mysite.com/test/ Inside test directory I have: index.php

  • 0

I have my website with a sub-directory:

http://www.mysite.com/test/

Inside “test” directory I have:

index.php
included-inside-index-file.php
another-included-inside-index-file.php
script.php

Now, how can i rewrite url with .htaccess so it works like this:

http://www.mysite.com/test --> access index.php
http://www.mysite.com/test/beautiful-url --> access script.php?parameter=beautiful-url
http://www.mysite.com/test/included-inside-index-file.php --> 404 error
http://www.mysite.com/test/another-included-inside-index-file.php --> 404 error
  • 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-17T19:09:30+00:00Added an answer on June 17, 2026 at 7:09 pm

    This is pretty straightforward. You need a generic rule for the beautiful-url, but preceded by rules which throw [R=404,L] for the scripts you want to hide.

    RewriteEngine On
    
    # First hide the includes
    # These could be simplified if they follow a pattern.
    # Here we'll list them individually though.
    RewriteRule ^test/included-inside-index-file\.php - [R=404,L]
    RewriteRule ^test/another-included-inside-index-file\.php - [R=404,L]
    
    # Then rewrite to the beautiful URL if the file doesn't exist.
    # The index.php will serve normally because it does exist
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^test/(.+)$ test/script.php?parameter=$1 [L]
    

    If you want to explicitly block direct access to script.php, you can match it inside THE_REQUEST. Place this after the rules which block access to the includes. I think this will work. If you tried to do it without the RewriteCond, you would get 404’s from the beautiful url rewrites.

    RewriteCond %{THE_REQUEST} script\.php
    RewriteRule ^. - [R=404,L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website, say http://mysite.com . I would like to put index.php in
Suppose I have a website hosted at the url: http://www.mysite.com/ Say this is hosted
I have a yii website under a sub directory e.g http://localhost/~username/maindirectory/yiiapp/ My htaccess file:
How to serve contents from different directory for virtual sub domains. Ex: http://www.website.com gets
Basically, I have a directory /website.com/ that contains an index.php . What usually happens
I was already running a sub-website under following path http://example.com/sub-site/ Now, I have created
I have a web site http://www.mydomain.com Here I have created a sub folder http://www.mydomain.com/products
I have two websites: http://example.com http://example.com/sub I have a page, let's say: http://example.com/sub/page1 Is
I have website based on Umbraco 5. I have installed contact form plugin (http://cultivjupitercontact.codeplex.com/).
I have a website let's say www.example.com and I have a subdomain something.example.com Both

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.