[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

.htaccess Mod Rewrite

I am running into a problem with mod-rewrite, my mod rewrite will not include pages that are index.html

example if i was to go to http://blah.com/people/  Instead of including the index.html where variable $pageincl is at it will just show the index.html as normal.

The htaccess looks like this.

Options +FollowSymlinks

# Avoid 500 error by passing charset
AddDefaultCharset utf-8

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.blah\.com [nc]
RewriteRule ^(.*)$ http://blah.com/$1 [L,r,nc]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?pageincl=$1 [QSA]

0
jags2ooo
Asked:
jags2ooo
  • 2
1 Solution
 
karlwilburCommented:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

These will only fire if the requested location does not exist as a file (!-f) or a directory (!-d)

As the index.html file exists, it is shown. Delete the index.html file and it will work.

You'll get:
http://blah.com/index.php?pageincl=index.html
for:
http://www.blah.com/index.html

and you'll get:
http://blah.com/index.php?pageincl=
for:
http://www.blah.com/


0
 
jags2oooAuthor Commented:
...  Umm let me try to re-explain   i go to http://blah.com/people/    instead of INcluding the Index.html file that is in people directory it will show Show me the file normally.     I would like it to include the index.html file that is in people if i go to use http://blah.com/people/

Example won't include index.php file:::::::::  http://bleach-network.com/information/bleach-characters/

example2:  will include a non Index file  http://bleach-network.com/information/bleach-shinigami

(it looks nasty cause the content is not made for that layout lol don't mind it :D just for testing)
0
 
karlwilburCommented:
Apache has a "DirectoryIndex" directive which tells Apache which file to use as a directory "index" if the HTTP request is for a directory (i.e. http://host.domain.tld/directory) rather than a specific file within a directory (i.e. http://host.domain.tld/directory/markup.html).
(e.g. DirectoryIndex index.html)

If the HTTP request is for a valid existing directory (remember ModRewrite will not redirect if the request matches an existing directory), Apache will look within that directory for a valid index file. If found (again, ModRewrite will not fire if that index file actually exists), Apache will server up that file.

So, the reason that you cannot use an index.php file is that when you request the directory without specifying a file, Apache interprets that as a request to serve the index file. (e.g. http://host.domain.tld/directory get interpreted as http://host.domain.tld/directory/index.html)

Now, if the DirectoryIndex directive does not have "index.php" in the list, then apache will not look for that file and the request, because it is interpreted as having an index file, will go unmatched thus allowing ModRewrite to take over.

So your options are:
1) rename the file from index.php to something else other than "index"
or
2) remove index.php from the DirectoryIndex directive.

Should you opt for #2, keep in mind that you can have more than one DirectoryIndex directive and they are allowed in all server contexts (i.e. server config, virtual host, directory, .htaccess)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now