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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:02:17+00:00 2026-06-11T16:02:17+00:00

I need a quick review of my updated .htaccess file please: RewriteEngine On #

  • 0

I need a quick review of my updated .htaccess file please:

RewriteEngine On
# Redirects errors to 404 page
ErrorDocument 404 /404.php

# Redirect index.php to site root
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,NC]
RewriteRule ^index.php$ http://www.mysite.com/ [R=301,L]

# Unless directory remove slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.mysite.com/$1 [R=301,L]

# Remove .php
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.mysite.com/$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/.]+)$ $1.php [L]

It’s fairly straight forward.

The first is a 404 redirect.
The second redirects http://www.mysite.com/index.php to http://www.mysite.com
The third removes slashes.
The fourth removes the .php extension.
The fifth resolves php.

Could someone cast an eye over this and give my code a quick sanity check please.

  • 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-11T16:02:18+00:00Added an answer on June 11, 2026 at 4:02 pm

    The below may make more sense at the top as you are redirecting the user and they will go through all of the .htaccess file again.

    What you’re actually doing here is if any of these are true you are telling the browser to go and load the website again from a different url “[R=301]“.

    # Redirect index.php to site root
    RewriteCond %{HTTP_HOST} ^mysite.com [NC]
    RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301]
    RewriteRule ^index.php$ http://www.mysite.com/ [R=301,L]
    

    Your other redirects are in a sensible order, if not a directory drop the slash, if a php drop the .php then resolve anything without a slash.

    Note this will result in a quite a few redirects if a user visits your website at certain url’s for example mysite.com/cake.php/ (which doesn’t exist)

    mysite.com/cake.php/ => mysite.com/cake.php
    mysite.com/cake.php => mysite.com/cake
    mysite.com/cake => http://www.mysite.com/cake
    http://www.mysite.com/cake resolves to http://www.mysite.com/cake.php – doesn’t exist
    404 => http://www.mysite.com/404.php
    http://www.mysite.com/404.php => http://www.mysite.com/404

    Though in summary it does what you are looking for!

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

Sidebar

Related Questions

Need some quick help with url rewriting. Currently using the following in an htaccess
Need quick help from win developers. Please correct me where I got it wrong.
I learned ruby on rails before php and need a quick answer. I'm trying
I need a quick REGEX to use with preg_replace() in PHP that will remove
I need a quick tip on using new File(File dir, String file) . I'm
I need a quick and easy way to store files with unique file names
I need a quick easy way to get a string from a file in
I have some (small amount) of data that I'll need quick access to on
Need some quick advice I am trying to access a object array but I
need a quick help here. I have a series of hyperlinks all with the

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.