2

The routing url is like 'my_website/:param'

But my location contain a folder name is as same as the params. So when I browse with http://my_website/apple. The browser will display the folder instead of pass the value 'apple' to the web.

How should I set the .htaccess?Thanks The following only work when the folder with same value is not exist.

<ifModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d

  RewriteRule ^.*$ - [NC,L]
  RewriteRule ^(.*) index.html [NC,L]
</ifModule>
2
  • Thanks for showing your htaccess file in your question, could you please do let us know link http://my_website/apple should be served by which file(eg--> .php file etc) from backend? Commented Feb 14, 2021 at 16:20
  • 1
    my front end use React.js. so it will be serve by index.html Commented Feb 14, 2021 at 16:23

1 Answer 1

4

Based on your shown samples, could you please try following. Please clear your browser cache before testing your URLs.

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.html [L]

OR if you are looking only for link which starts with apple then try following.

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^apple index.html [NC,L]

Problem in OP's tried code: RewriteRule ^(.*) index.html [NC,L] will create an loop because there is no condition mentioned, so its going true each time for each uri.

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

Comments

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.