3

On production I have domain http://xxxx.com. In root folder I added .htaccess:

<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews -Indexes </IfModule> RewriteEngine On RewriteCond %{REQUEST_URI} !^/public/ RewriteRule ^(.*)$ /public/$1 [L,QSA] </IfModule> 

And when I type in the browser: http://xxxx.com it works.

The same .htaccess file I have on my machine. I use XAMPP. And it doesn't work. When I type:

http://localhost:8082/myfolder 

I get 404. When I type:

http://localhost:8082/myfolder/public 

It works. What is the difference between url in my hosting and on my local machine?


For the first answer: this is a screen, maybe I'm doing something wrong (.htaccess is in the root folder), maybe .htaccess in the public folder is wrong: rewrite url htaccess

1 Answer 1

1

This should work for you:

<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews -Indexes </IfModule> RewriteEngine On RewriteRule !^public/ public%{REQUEST_URI} [L,NC] </IfModule> 

The problem with your rule is that you're checking this condition:

RewriteCond %{REQUEST_URI} !^/public/ 

Which actually checks for URI /public from web root however you have your site inside a subfolder locally. Here RewriteRule !^public/ will check if public/ is not there at the start after the current directory context, which will work the same in site root as well in a subdirectory.

Similarly for rewriting also make sure you don't use / before public/ to allow it to use a relative path.

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

3 Comments

Thanks for response, but now when I type localhost:8082/xxxx/ it change url to localhost:8082/xxxx/public/xxxx/ and I get 404
Your .htaccess should be placed in root folder or in public ?
This .htaccess should be placed in root and this won't change URL, it will just rewrite. Test in a new browser or clear browser cache. Try testing with a new URL i.e. localhost:8082/foo123/

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.