1

I'm using Wamp on my dev machine to develop a project. This is my .htaccess:

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?$1 [L] RewriteBase /project/ 

This is put in localhost/project, so that any requests like localhost/project/something , are routed to localhost/project/index.php/something

However, they are being routed to localhost/index.php/something

I suspect it has something to do with how I'm using RewriteBase. How do I fix it?

2 Answers 2

3

You need to remove the leading slash in your rule:

# no slash---------v RewriteRule ^(.*)$ index.php?$1 [L] 

Apache kind of guesses whether the targets of a RewriteRule is a URL-path or a file-path. When it starts with a slash, it assumes it's a URL-path and that it's absolute, so it'll go to the document root's index.php. Without the slash, it'll either guess a file-path or use the rewrite base to help determine which to use.

You should also move the RewriteBase directive above your rule.

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

Comments

1

Why not put the base in the rewriterule?

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /project/index.php?$1 [L] 

Edit:

This question might help you: htaccess RewriteBase

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.