简体   繁体   English

为404错误设置.htaccess

[英]Setting .htaccess for 404 error

So, I new to .htaccess. 因此,我是.htaccess的新手。 My current .htaccess file: 我当前的.htaccess文件:

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. 如果我在'simpleblogsys /'之后键入username,它将定向到页面。 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. 如果找不到该页面,我想设置一个错误404文档。 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: 对于404,如果您没有看到有效的用户名,则可以致电:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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