0

enter image description here I have root file and in root file public => index.php.I created .htaccess in root and wrote this code

RewriteEngine on RewriteCond %{REQUEST_URI} !^public RewriteRule ^(.*)$ public/$1 [L] 

to redirect from root to public/index.php but it is not working. localhost is wamp(apache)

8
  • 1
    root file public ? That could mean anything, please show exact folder structure Commented Nov 14, 2020 at 12:51
  • Thanks for showing your efforts in your question. Could you please do let us know from which url to which url you want to redirect more clearly, kindly add that info in your question. Commented Nov 14, 2020 at 12:52
  • procject(root folder)=>public=>index.php Commented Nov 14, 2020 at 12:53
  • .htaccess this file is in project(rootfolder) Commented Nov 14, 2020 at 12:54
  • 1
    You .htaccess file in in the code folder and not the public folder. I would guess that the public folder is your DocumentRoot or at least it probably should be Commented Nov 14, 2020 at 13:05

1 Answer 1

1

If I get your question correctly, could you please try following. This simply checks if REQUEST_URI is null then move further to rewriterule to redirect it in backend to index.php file

RewriteEngine ON RewriteBase / RewriteCond %{REQUEST_URI} ^/$ RewriteRule ^(.*)$ /public/index.php [L] 

IMHO When you are using public/$1 in right side of your rewriterule $1 is empty since it's REQUEST_URI value is NULL because you are hitting base url, so its better to write /public/index.php there.

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

10 Comments

RewriteEngine ON RewriteCond %{REQUEST_URI} ^$ RewriteRule ^(.*)$ /public/index.php [L] it is not working
@yunusdjanov, could you please do let me know what error are you getting?
The requested resource / was not found on this server.
REQUEST_URI string starts with a leading slash. If you want to match against root dir then the condition pattern should be ^/$ .
@AmitVerma, Thanks Amit for correcting it, totally missed it, Thank you, cheers and happy learning.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.