skip to Main Content

I’m trying to remove: "site.php" from my url:s, which look like
"example.com/custom-foldername/site.php", so the url:s would look like "example.com/custom-foldername"

Currently it’s not working at all. Basically my site just doesn’t change the url. I know that the .htaccess file is being read, because if i write junk code in it, it gives error 500.

Here is my current .htaccess code

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Options -Indexes
RewriteRule ^site.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site.php [L]
</IfModule>

2

Answers


  1. Chosen as BEST ANSWER

    UPDATE: I solved this my myself while ago, but forgot to update

    So, i found the solution and here's my current .htaccess file, if someone is ever having the same problem

    RewriteEngine On
    RewriteBase /
    Options -Indexes
    DirectoryIndex site.php site.html
    

    When user "asks" for folder directory (example.com/cats) apache looks for "site.php or site.html" files inside it. (example.com/cats/site.php) If it finds either on of them it displays it to the user as (example.com/cats). If either file isn't found it gives normal "404 not found error"


  2. The code you posted is a front-controller pattern – it rewrites every request for non-existent files to /site.php in the document root (not /custom-foldername/site.php).

    And nor will a RewriteRule pattern like ^site.php$ match a request like /custom-foldername if the .htaccess file is in the document root.

    I’m trying to remove site.php from my URLs…

    From all your URLs? Is site.php present in all your URLs? So, site.php is your front-controller?

    If site.php really is your front-controller then try something like the following instead:

    Options -Indexes
    
    RewriteEngine On
    RewriteBase /custom-foldername
    
    RewriteRule site.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ site.php [L]
    

    This rewrites everything that doesn’t map to a physical file or directory to /custom-foldername/site.php.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search