3

I am running XAMPP for Windows 5.6.11. I have the following PHP file:

C:\xampp\htdocs\www.johndoe.com\index.php

which I am accessing as

http://localhost/www.johndoe.com/

As a matter of fact I need to access the following page:

http://localhost/www.johndoe.com/?value=about

as either of the following two:

http://localhost/www.johndoe.com/about/
http://localhost/www.johndoe.com/about

so I have the following in my .htaccess file:

RewriteEngine on
RewriteRule ^www\.johndoe\.com/about/?$ www.johndoe.com/?value=about

However, this is not working, as accessing the former sites gives me a 401 (not found).

Here is what I have in C:\xampp\apache\conf\httpd.conf:

<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
</Directory>

What must I do to get my .htaccess file to be parsed and carry out the substitution I'm after?

I have tried placing the following in C:\xampp\apache\conf\httpd.conf:

<Directory />
    AllowOverride all
    Require all allowed
</Directory>

but have had no luck with it. I have even tried changing my .htaccess file to the following:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteBase /www.johndoe.com/
RewriteRule ^about/?$ ?value=about

but I'm still getting the 404 not found error message.

John Sonderson
  • 3,238
  • 6
  • 31
  • 45
  • Are you getting a 401 or a 404? – Pekka Sep 06 '15 at 23:02
  • Well, I'm not sure what happened. Earlier I was getting the message about there being a "server configuration error: page not found", and now it is redirecting me to `http://localhost/dashboard/` (Welcome to XAMPP). – John Sonderson Sep 06 '15 at 23:04
  • The /johndoe.com/index.php file works? – Pekka Sep 06 '15 at 23:05
  • Yes, the `http://localhost/www.johndoe.com/index.php` works and the same can be accessed as `http://localhost/www.johndoe.com/`. – John Sonderson Sep 06 '15 at 23:06
  • Where is the .htaccess file located? With that RewriteBase it should be in /www.johndoe.com I think – Pekka Sep 06 '15 at 23:07
  • That's where the file is at the moment. Does it matter where the RewriteBase directive goes? Should I delete the RewriteBase directive? Should I place the .htaccess file one level up from /www.johndoe.com/ right inside C:\xampp\htdocs? I can't get things to work. – John Sonderson Sep 06 '15 at 23:11
  • 1
    It's often a bit trial and error with this... what I'd do is start small, put the .htaccess and the index.php in the root directory, reomve the RewriteBase and see whether any rewriting takes place then. A good way to find out whether the file is being acknowledged at all is to put an intentional syntax error in it (`RewriteBrase`) and see whether it throws a 500 error. A good way to test whether a rewrite rule works is to specify an external site as the target (`RewriteRule ^about/?$ http://example.com`). Also do replace the `?menu1=about` with the full name of the index.php file. Good luck! – Pekka Sep 06 '15 at 23:15
  • 1
    Thanks. I don't know what was wrong, but it's working now: no modification to `C:\xampp\apache\conf\httpd.conf`, no `RewriteBase` directive, the `.htaccess` is inside www.johndoe.com, and the following works: `RewriteEngine on`, `RewriteRule ^about/?$ ?menu1=get-in-touch` (no `.htaccess` file in the directory above). – John Sonderson Sep 06 '15 at 23:20

1 Answers1

4

As it turns out, with the default XAMPP configuration there is no need to C:\xampp\apache\conf\httpd.conf, hence no need to restart Apache as we are just making changes to C:\xampp\htdocs\www.johndoe.com\.htaccess. As this post on RewriteBase explains, we do not need RewriteBase since we will not use absolute paths in the destination links for .htaccess rules. Since relative links in these destination rules will be relative to the directory we are serving out of, we need delete the www.johndoe.com directory from the rule, as follows:

  • Place the .htaccess in ``C:\xampp\htdocs\www.johndoe.com`.

  • Place the following rewiterule in it:

      RewriteEngine on
      RewriteRule ^about/?$ index.php?value=about
    
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
John Sonderson
  • 3,238
  • 6
  • 31
  • 45