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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:15:39+00:00 2026-05-16T23:15:39+00:00

On a LAMP server, I want the URL http://example.com/index.php to be rewritten to simply

  • 0

On a LAMP server, I want the URL

http://example.com/index.php

to be rewritten to simply

http://example.com

My current .htaccess file is as follows…

IndexIgnore *

ErrorDocument 400 /index.php?module=error&action=error
ErrorDocument 401 /index.php?module=error&action=error
ErrorDocument 403 /index.php?module=error&action=error
ErrorDocument 404 /index.php?module=error&action=error
ErrorDocument 500 /index.php?module=error&action=error

RedirectMatch 301 ^/media/$ /
RedirectMatch 301 ^/media/documents/$ /
RedirectMatch 301 ^/media/graphics/$ /
RedirectMatch 301 ^/media/photos/$ /
RedirectMatch 301 ^/library/$ /
RedirectMatch 301 ^/library/css/$ /
RedirectMatch 301 ^/library/ht/$ /
RedirectMatch 301 ^/library/js/$ /
RedirectMatch 301 ^/library/php/$ /

RewriteEngine on
RewriteBase /

RewriteRule ^home$ /index.php?module=home&action=frontpage
RewriteRule ^home/$ /index.php?module=home&action=frontpage
RewriteRule ^home/([^/\.]+)$ /index.php?module=home&action=$1
RewriteRule ^home/([^/\.]+)/$ /index.php?module=home&action=$1

RewriteRule ^cv$ /index.php?module=home&action=cv
RewriteRule ^cv/$ /index.php?module=home&action=cv

RewriteRule ^release$ /index.php?module=release&action=release
RewriteRule ^release/$ /index.php?module=release&action=release

RewriteRule ^photos$ /index.php?module=gallery&action=album&album=general
RewriteRule ^photos/$ /index.php?module=gallery&action=album&album=general

RewriteRule ^gallery$ /index.php?module=gallery&action=album&album=general
RewriteRule ^gallery/$ /index.php?module=gallery&action=album&album=general
RewriteRule ^gallery/([^/\.]+)$ /index.php?module=gallery&action=album&album=$1
RewriteRule ^gallery/([^/\.]+)/$ /index.php?module=gallery&action=album&album=$1
RewriteRule ^gallery/([^/\.]+)/([^/\.]+)$ /index.php?module=gallery&action=album&album=$1$&page=$2
RewriteRule ^gallery/([^/\.]+)/([^/\.]+)/$ /index.php?module=gallery&action=album&album=$1$&page=$2
RewriteRule ^gallery/([^/\.]+)/([^/\.]+)/([^/\.]+)$ /index.php?module=gallery&action=item&album=$1$&page=$2&item=$3
RewriteRule ^gallery/([^/\.]+)/([^/\.]+)/([^/\.]+)/$ /index.php?module=gallery&action=item&album=$1$&page=$2&page=$3

RewriteRule ^handouts$ /index.php?module=home&action=handouts
RewriteRule ^handouts/$ /index.php?module=home&action=handouts

RewriteRule ^links$ /index.php?module=home&action=links
RewriteRule ^links/$ /index.php?module=home&action=links

RewriteRule ^contact$ /index.php?module=home&action=contact
RewriteRule ^contact/$ /index.php?module=home&action=contact

RewriteRule ^login$ /index.php?module=authentication&action=login
RewriteRule ^login/$ /index.php?module=authentication&action=login
RewriteRule ^logout$ /index.php?module=authentication&action=logout
RewriteRule ^logout/$ /index.php?module=authentication&action=logout

RewriteRule ^copyright$ /index.php?module=home&action=copyright
RewriteRule ^copyright/$ /index.php?module=home&action=copyright

RewriteRule ^error$ /index.php?module=error&action=error
RewriteRule ^error/$ /index.php?module=error&action=error

How should I edit my .htaccess file to accomplish this basic rewrite? Also, any other feedback with regard to my .htaccess code would be greatly appreciated.

Thanks in advance!

  • 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-16T23:15:41+00:00Added an answer on May 16, 2026 at 11:15 pm
    RewriteRule ^/index.php$ /
    

    but this doesn’t make sense, as / is likely to serve index.php.
    if you have an index.php file in your directory and don’t want to serve it as default, its a very strange configuration! but possible of course… if you have specified different DirectoryIndex ‘es in your webserver config.

    perhaps you want to redirect index.php to / ???

    in this case you can put a RedirectMatch in your config like RedirectMatch 301 ^/index.php$ / but i would rather recommend to do this in your php file directly looking at your $_SERVER["REQUEST_URI]; but this is a matter of style. i personally like to have as much control in my application if possible and only move to the server config if its faster or necessary…

    EDIT:

    after your comment which cleared what you actually need, I can give you two solutions.

    Redirect / RedirectMatch won’t work because you can’t do it conditinally, where you can check for the actual request uri. additionally the finally served url will be used for redirectmatching. which means AFTER the redirect to index.php by apache via the DirectoryIndex directive.
    so those methods wont be able to tell the difference between / and /index.php.

    so you need to do it either in your php file which is

    version 1:

    see if $_SERVER['REQUEST_URI'] ends with index.php, this will only happen if its actually requested (typed into the browser bar). there you can do a redreict using header("Location: ...").

    version 2:

    using mod rewrite which is also able to do redirects and can do it on conditions.
    in included the configuratino you have (DirectoryIndex) for demonstrating purposes.
    You actually only need the RewriteCond and RewriteRule line.

    DirectoryIndex index.php
    
    RewriteEngine On
    RewriteBase /
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
    RewriteRule ^index\.php$ http://www.yourdomain.com/ [R=301,L]
    

    i am not sure wheter its possible to leave your domain and just type /, you can look that up.
    this will only if the request url actually is /index.php apply the rewriterule which does the redirect.

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

Sidebar

Related Questions

I have a PHP script running on my LAMP server that requires certain files
I have a php mail script sitting on a LAMP vps server. The script
I have a rackspace cloud where I want to set up LAMP. the server
I have a LAMP server. I have only Http(80) and HTTPS(443) ports are open.
I installed LAMP on a fresh server and Zend Framework aswell. I now want
I have a file called init.php which I want to get automatically included in
I have a LAMP server where I've run the following commands to set permissions
I'm running my own LAMP server locally. Something i need to setup? Should it
I have setup the basic LAMP server on Ubuntu 11.10 and had a few
This one is a little confusing to me. I'm running a LAMP server with

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.