PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 3, 2022

[FIXED] Why I can't access some pages or directories on my localhost XAMPP?

 July 03, 2022     .htaccess, localhost, xampp     No comments   

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:

  1. I have a project running in my XAMPP

(Edited localhost to 127.0.0.1:80)

(Edited htdocs to my workspace folder)

  1. 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]
  1. I also have Visual Studio's Live Server Plugin which generates random amount of port. (Might be interfering?)
  2. Sometimes I have access to index.php sometimes I don't.
  3. 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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing