Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

leadegroot's avatar

.html url not returning view (or even 404 error view)

I'm starting a new project to rewrite an existing, mostly static, project in Laravel.

As such, I really, really want to retain the existing URLs, which mostly end in .html

However, I am finding that all routes to .html URLs return what seems to be the Apache Not Found error page - not the correct view, not even the Laravel 404 error page

This is even from a completely unedited install.

Ie, it is returning:

The requested resource /something.html was not found on this server.

If I change the address to /somethinghtml (or anything else without a dot) I get the correct Laravel 404 error:

Sorry, the page you are looking for could not be found.

Is there something I have to do to get Routes to take a '.' in the URL?

Thanks, guys!

0 likes
24 replies
jlrdw's avatar

See if they will load with an a href... should.

leadegroot's avatar

Do you mean click on a link that loads a page with a .html url?

No, its not different

(that was where I started: build homepage, put link on page, click link to build next view... wait, why is that an error?)

Snapey's avatar

check your .htaccess file. all unknown requests should be directed to index.php

jlrdw's avatar

I just put an html file under public and linked like

<a href="public/htmlfiles/test.html">trythis</a>

Works like a champ. You shouldn't need routes to html files. @Snapey you said all unknown requests should be directed to index.php, Not an html file, if that were true you couldn't call up images from the database.

leadegroot's avatar

@jldrw No, I want Laravel to process these files - I dont want them static in the public folder!

Most of them are static, but some of them are current .php files with a .html address overlay via htaccess rewrite, so I will need the routing to direct to a controller or view for those...

@Snapey this is an out of the box install (I went back to a new one) so I havent touched the .htaccess - surely there is a standard way to use .html addresses?

leadegroot's avatar

Addresses ending in .php do the same thing - seems to be anything with a '.' in the url :(

jlrdw's avatar

You need to change your htaccess to have the .php showing is all, but I'd get those files converted to laravel mvc as soon as possible, Ikes I am glad I'm not having to deal with something like that, best of luck to you.

jlrdw's avatar

@leadegroot was curious, so I tested. I couldn't get html working, but I renamed to test.php:
Route

Route::get('htest', array('uses' => 'PetsController@htest'));

Controller code

public function htest()
    {
       return view('pet/test'); 
    }

So renaming test.html to test.php did work. So url like whatever /something/htest works without an extension.

leadegroot's avatar

Well, if I was going to rename, I would drop the suffix completely - the idea is to keep the existing URLs, most of which are .html...

but... #confused I don't see .php in your Route?

jlrdw's avatar

The extension isn't needed, laravel router is using the part in routes htest do get what I told it in the 'uses' => 'PetsController@htest' part. That's how the router works. So you can have the .php extensions. There should be a way to route to an html extension, you could try adding to htaccess. I am not sure if it's laravel that requires a php file in the views. I couldn't get the router to work on test.html only test.php.
Search stackoverflow also for this, as I have never needed to route to an html file.

leadegroot's avatar

Hmmm... I dont know how you are doing it!

If I return

/about.djfbdf

I get an apache 404 page - it never hits Laravel if there is a '.' in the path :(

I thought I had something with:

Route::get('about.{extension}', function () {
    return 'about';
});

but it never reaches the routes file :(

jlrdw's avatar

Don't have the dot in the URL.
Put one of the word in the router you want to use for that file, like I used htest to bring up test.php. test.php is in a view. The controller called return view('pet/test');
I tested in version 5.1 if you are using 5.2 you need the Web middleware, sorry.

leadegroot's avatar

Ah. But the point is to have a dot in the URL... :)

OK, it appears that Laravel cannot do this, which is strange, and will change some of my plans for redevelopment (the second site I was going to redevelop is doing a bit dodgily in the SERPs atm, and I am Not going to make things worse by changing the URLs...) but I think I will just change the URLs on this site. Its poor practice to do so, but its a bit of an eh site, so it doesn't matter that much.

jlrdw's avatar

Read my edit, and you can still have the file names in the router just don't use the extension, so instead of whatever.php it would just be whatever.

1 like
Snapey's avatar

@jldr

As such, I really, really want to retain the existing URLs, which mostly end in .html

thus not breaking seo and bookmarks

@Snapey you said all unknown requests should be directed to index.php, Not an html file, if that were true you couldn't call up images from the database.

No, you are incorrect. all UNKNOWN files. If you request a .jpg file for instance, and it exists, then it can be served by the web server. If you access something for which there is no real file, then it should go to index.php

There should be no problem with .html requests being routed to a specific controller.

Snapey's avatar

As I said, check your htaccess. What you want to do is perfectly possible.

This works fine on my apache setup;

    Route::get('testing.html', function(){
        return 'hello from testing.html';
    });
leadegroot's avatar

But I havent changed the .htaccess! - I have this happening on an out of the box 5.2 install!

leadegroot's avatar

Well, at least its not a 5.2 bug - I just installed 5.0 and its happening there too. Steps:

  • install 5.0
  • load root page (to confirm it runs) - success
  • load /about.html - apache error
  • load /about - laravel notfoundhttpexception

I'll have to look at the .htaccess tomorrow... but its a very plain version. I dont see why it wouldnt be firing the ^ :(

Snapey's avatar

I have this happening on an out of the box 5.2 install!

That does not mean that your server setup is also 'out of the box'

What does your .htaccess file contain and is it in the public folder?

When you access your site you don't have to specify anything in the path do you (like localhost:8000/public/)?

leadegroot's avatar
leadegroot
OP
Best Answer
Level 7

The default, yes and no.

Reporting back - I noticed the server was running an old version of PHP (5.4.10) and upgraded to 5.6.10 and (after several days mucking around to get everything else working...) it didnt make any difference. I've started a homestead VM running and it runs perfectly, so its some oddity of the config on that server. Cant imagine what :( Anyway, I got it working via a VM, so all good :)

Snapey's avatar

@jb99 it would be better if you started your own thread then you would be notified of any updates and responses would not need to mention you

Have you checked your routes with php artisan route:list ?

jb99's avatar

@Snapey Thanks, I meant to do that and then didn't. I'll repost starting my own thread.

Real quick - I'm using Laravel. This is from the first series, The PHP Practitioner and the lessons haven't reached Laravel.

Please or to participate in this conversation.