简体   繁体   中英

Setting .htaccess for 404 error

So, I new to .htaccess. My current .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /simpleblogsys/profile.php?username=$1

So I have created login and registration for the site I'm testing. If I type username after 'simpleblogsys/', it directs to the page. Example:

http://localhost/simpleblogsys/TestUser1

The problem is, if I put a slash the username and type something random, Like this:

http://localhost/simpleblogsys/TestUser1/blablabla

it loads the page without any scripts or stylesheets. I want to setup a Error 404 document if the page wasn't found. What should I do?

Scripts and Stylesheets are not found most likely because you are calling them with a relative path...

js/whatever.js

you'll need to use a path from the root...

/assets/js/whatever.js

For the 404, if you are not seeing a valid username you can call:

header("HTTP/1.0 404 Not Found");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM