繁体   English   中英

输入错误的 url 时重定向到 404 页面

[英]Redirecting to 404 page when wrong url is entered

我有一个 404 错误页面并尝试了从该链接生成的以下代码。 但是当输入错误的 URL 时,它会重定向到主页,而不是 404 错误页面

<IfModule mod_rewrite.c>
RewriteEngine On
ErrorDocument 404 https://www.rcis.in/404.php
</IfModule>

我已经在 htaccess 文件中添加了代码。 以及如何从 URL 中删除文件扩展名。 下面是我尝试过的代码

 #Remove extension
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^([^\.]+)$ $1.php [NC,L]

我尝试了下面从上面提到的那个网站生成的代码

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/?(.*).(php)$ /$1 [R=301,L]

</IfModule>

我该如何解决这两个

先感谢您

下面的代码将从 URL 中删除 php 扩展

RewriteEngine On
# for 404 redirection
ErrorDocument 404 https://www.yourdomain.in/404
# below code rewrites php extention
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
# Remove php extention
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

Hence the url https://www.yourdomain.in/404 will load https://www.yourdomain.in/404.php

暂无
暂无

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

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