0

I have an test project in sub directory (G:/wamp/www/test) which has only index.php and .htaccess

I tried to make friendly urls by adding RewriteRule to .htaccess like this:

RewriteEngine on

DirectoryIndex index.php

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

RewriteRule ^/*$ index.php

This worked on all other projects but it is not working on this one. When I want to access an URL like this:

http://localhost/test/TESTING_URL I am getting default 404 Not Found page. However, if I go like this: http://localhost/test/index.php/TESTING_URL - it works.

Apache error log is giving me the following error:

File does not exist: G:/wamp/www/test/TESTING_URL

1 Answer 1

1

The following worked for me:

RewriteEngine on

RewriteBase /test/

DirectoryIndex index.php

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

Make sure that this .htaccess file is in the directory test and that there aren't any conflicting rewrite rules in any .htaccess file at a higher level.

Otherwise the only difference is the addition of the RewriteBase line.

Sign up to request clarification or add additional context in comments.

3 Comments

Still the same thing happens
I'm sorry, I realize now that you are in a subdirectory, the rewritebase should refer to that subdirectory. Additional comments added in the answer body.
Well, you see, I have moved .htaccess file from subdir to root dir (www) and it works good but I also tried removing it from root and adding your code into subdir, it doesn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.