skip to Main Content

Trying to setup basic routing on godaddy, but only the first two cases work with the root but not for cases with words – browser returns Not Found. My guess is that instead of routing case it searched for a folder/file with the word in URL, nothing I tried worked.

.htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php

index.php:

<?php

$request = $_SERVER['REQUEST_URI'];
$viewDir = '/';

switch ($request) {
    case '':
    case '/':
        require __DIR__ . $viewDir . 'home.html';
        break;

    case '/test':
        require __DIR__ . $viewDir . 'boost.html';
        break;
}

Hosting type: Deluxe Linux Hosting with cPanel

Even with deleted .htaccess code the first two cases in index.php work. I renamed index.php file and even root routing doesn’t work – which means htaccess never worked. Godaddy on shared hosting doesn’t allot apache config access but allows to configure .htaccess file.

2

Answers


  1. Chosen as BEST ANSWER

    Changing the rule a bit worked: RewriteRule ^(.*)$ index.php?$1 [QSA,L]

    Thanks everybody for the helpful comments!


  2. Instead of the mod_rewrite old recipes we still suffer and see, all questions like this should just go to a more modern simple approach which does not need mod_rewrite at all.

    DirectoryIndex index.php # if necessary/needed
    FallbackResource /index.php
    

    The first one will look for index.php when a directory path is requested, as in with a trailing slash.

    The second one will load /index.php when a request points to a non-static or non-existent element.

    Modules needed for this: mod_dir

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