Page 1 of 1

Mod_rewrite

PostPosted: 18. June 2014 02:46
by BBone1
I have xampp lite 1.8.3
I would like to enable mod_rewrite and for a start in xampp/apache/conf /httpd.conf the line LoadModule rewrite_modules/mod_rewrite.so is uncommented already. Searching I found to uncomment and to and to have all AllowOverride All.
So in Server name localhost:80 and the following directory changed to All. The next directory <Directory "C:/xampp/htdocs"> it already has
Options Indexes FollowSymLinks Includes ExeCig
AllowOverride All and Require all granted. The next directory <Directory "C:/xampp/Cgi_bin"> All and Require granted.
When I load phpinfo() on the server it doesn't show in the loaded modules list, Mod_rewrite as loaded in that list.
With the apache documentation it says recomemded to put rewrite Rule etc in VirtualHost block and I'd like to do that, to get used to it etc.
In xampp/apache/conf/extra/httpd-vhost.conf it has examples for two sites using one host.
Searching I found using two blocks for such as www.example.com and www.example.org which is what is explained in the vhost file.
Also searching to set up vhost I found and assume for it to be so for one domane hostname.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot C:/xampp/htdocs
SeverName localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExeCig
AllowOverride All
Order allow deny
Allow from all
</Directory>
Then I assume
<IfModule mod_rewrite.c>
Rewrite Engine On
etc for the condition and rules
</IfModule>
Thanks for your advice and I hope I don't seem a dummy.
Could you tell me if I'm on the right path in setting it up and if the rewrite module is loaded. Does the file in xampp/apache/cof/original/httpd.conf have any bearing as it is the same as the other except #LoadModule rewrite_module Modules/mod_rewrite.so is commented as I have here.
Thanks for your time
BBone1

Re: Mod_rewrite

PostPosted: 18. June 2014 05:28
by Altrea
BBone1 wrote:Searching I found to uncomment and to and to have all AllowOverride All.

Sorry, but thats not good practice. Set AllowOverride to exactly this value you need and only at the places you need that.

BBone1 wrote:So in Server name localhost:80 and the following directory changed to All.

Undo your changes expecially for the Block <Directory />

BBone1 wrote:With the apache documentation it says recomemded to put rewrite Rule etc in VirtualHost block and I'd like to do that, to get used to it etc.

You don't need that.
rewrites are strictly application dependend so i would define them as near to your application as possible (in an .htaccess file inside the root directory of your application).

BBone1 wrote:Also searching to set up vhost I found and assume for it to be so for one domane hostname.
Code: Select all
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot C:/xampp/htdocs
    SeverName localhost
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" common
    <Directory "C:/xampp/htdocs">
        Options Indexes FollowSymLinks Includes ExeCig
        AllowOverride All
        Order allow deny
        Allow from all
    </Directory>


Use code-BBTags at this board here to make your code more readable.

Your vhost definition is incorrect:
  • At the end is a </VirtualHost> missing
  • There is a comma missing between allow deny
Two more hints:
  • Order, Allow from and Deny from are old access syntax. Use the new one
  • htdocs is already configured by an Directory Block in your httpd.conf, no need to do that in your vhost again.

BBone1 wrote:Could you tell me if I'm on the right path in setting it up and if the rewrite module is loaded.

Whether or not the rewrite module is loaded for your request nobody can say this except you.
By default mod_rewrite is activated in XAMPP.
As already said i would use an .htaccess file for it.

BBone1 wrote:Does the file in xampp/apache/cof/original/httpd.conf have any bearing

No file inside xampp/apache/conf/original/ is important, that are only templates.

best wishes,
Altrea