Mod Rewrite - use with .htaccess - HELP!

Hi Folks

We host websites on Apache servers. One of our client's web designers has asked us to allow the use of Mod_Rewrite, preferably with .htaccess, and I have absolutely no idea how to implement this feature.

Can someone please explain, in words of one syllable, step by step how I set this up for this particular virtual site on the server?

Many thanks!
Chris KenwardIT Tech SupportAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

In httpd.conf put this statement

<Directory "/path/to/root/of/vserver>
    AllowOverride +FileInfo

This will allow .htaccess to turn on RewriteEngine. And if You ask, this is valid only within Directory directive, You can't set it per VHost.

And make sure, mod_rewrite is compiled into apache (or dso)
'httpd -l' will show You compiled-in modules.
'LoadMoule' directives will show You additional modules loaded from 'libexec' directory of apache.
If you're on shared server you can't enable mod_rewrite if it is disabled on a server because you don't have root access. But you can test.

Put this into your htaccess file and then type some unvalid url. If you can use mod_rewrite on your server you should see redirect with info on file that didn't existed.


RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) http://%{HTTP_HOST}/path_to_php_file.php?dat=%{REQUEST_URI}&%{QUERY_STRING}

You have to do this in two steps:
step1: Ask apach to identify the .htaccss file. You can do this in this way in the httpd.conf.

Inside the <Virutalhost> </VirtualHost>  entry of that domain put:
<Directory "/var/www/html/site1">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
  Allow from all
AccessFileName .htaccess
<Files ~ "^\.ht">
    Order allow,deny
    Deny from all

if /var/www/html/site1 is the document root for the domain.

your have to put the rewrite rules in the .htaccess file. The location of the .htaccess file can be at /var/www/html/site1 or its child tree.

OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

The above is untrue.
modrewrite requires
Options FileInfo
in the Directory scope
(or, as I posted in first post, AllowOverride FileInfo, which allows to override it in .htaccess file)
Point is if he host his sites on shared server he do not have access to httpd.conf in a first place. So he cannot add any lines to httpd.conf.

Only think he can do is to check if mod rewrite is enabled (allowed) on server.

Yes, 'gruntar' You are right.
'bimal_linux's post is wrong, as the configuration he provided does not allow to use mod_rewrite.

And as the author said 'one of our clients', I assumed, that the author has access to httpd.conf.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.