Issue
First of all, I already dug the internet but I couldn't find a solution.
So, Here's what I did to my website and my step-by-step questions:
- I have a project running in my XAMPP
(Edited localhost to 127.0.0.1:80)
(Edited htdocs to my workspace folder)
- I tried setting up an
htaccess
file for my website just to remove php and html extensions:
Here you can see it's content:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
- I also have Visual Studio's
Live Server
Plugin which generates random amount of port. (Might be interfering?) - Sometimes I have access to
index.php
sometimes I don't. - I don't have access to
/icons/...
directory all the time.
I really need a serious help right here or I might lose my temper losing my project :(
My best of appreciations to the solver in advance <3
Solution
That rewriting configuration you posted makes no sense. How should the rewriting engine decide which rule to use? Do you expect it to somehot magically guess ?
Take a look at this instead and work out the difference:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
A better variant would be that:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [END]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [END]
And a general remark: you should always prefer to implement such rules in the actual http server's host configuration. Distributed configuration files (".htaccess") come with a number of disadvantages, they should only be used if no other alternative exists (read: if you are using a cheap hosting provider and have no access to the real configuration).
Answered By - arkascha Answer Checked By - Willingham (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.