2

I've installed Xampp as a web server and want to make clean URLs for one of my projects. So I put these simple lines in .htaccess file in the root of this project:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Also I made links in this project like this:

<a href="/about/">About Us</a>

I expected to go to localhost/this_project/about/, but it does not work. I go to localhost/about/ and this is wrong. How can I solve this problem?

I also have put this line in the 2nd line of .htaccess file, but no change happened.

RewriteBase /this_project/

Attention: There are many directories in htdocs folder for each project.

Mohammad Saberi
  • 12,864
  • 27
  • 75
  • 127
  • You want 1 .htaccess to control behaviour of all the virtual hosts you have in your Apache? – N.B. Nov 28 '12 at 16:40
  • @N.B. I need 1 .htaccess file for each specific project located in a directory in htdocs folder. – Mohammad Saberi Nov 28 '12 at 16:43
  • Don't use .htaccess files for this. Such stuff belongs in the main config of the http server. – arkascha Nov 28 '12 at 16:43
  • @arkascha I have to do it. Because I have upload all files of each project on its web hosting with its specific mod_rewrite rules. They can be different in each project. – Mohammad Saberi Nov 28 '12 at 16:50
  • @MohammadSaberi ah, ok that is different. I did not learn that from your question. I agree, in such case you do want to use .htaccess file. This is what they are meant for. Only this. :-) – arkascha Nov 28 '12 at 16:55
  • @arkascha now do you have any idea to solve this problem? – Mohammad Saberi Nov 28 '12 at 17:02
  • Sorry, I'm not good with .htaccess files, I try to avoid them where possible, since I find their configuration arkward and error prone. Just a suggestion: you sure there really should be a `/` before the `index.php` in the rule? – arkascha Nov 28 '12 at 17:19
  • @arkascha I removed `/` from `/about/ and problem solved now. But this is not the solution. I have to solve it completely – Mohammad Saberi Nov 28 '12 at 17:27
  • I guess you mean you removed the _second_`/` inside `/about/`? If that helps than probably your problem is that the `/` drops you into another directory. That is the annoying thing with .htaccess file style rewriting: it is pure horror to debug. BUT: since you are testing your setup on a local server where you have administration access, why don't you enable rewrite logging? It shows you exactly what is going on inside the rewrite engine. Check the manual of mod_rewrite for the commands `RewriteLog` and `RewriteLogLevel`. Chose a level of 7, `tail -f` the log file and make a single request. – arkascha Nov 28 '12 at 20:38

1 Answers1

0

You htaccess looks OK so I guess you are missing

AllowOverride All

In the VHOST <directory> block. If you server will fail after you add AllowOverride make sure you enabled mod_rewrite.

Lukasz Kujawa
  • 3,026
  • 1
  • 28
  • 43