dongye4192 2016-08-07 00:53
浏览 128
已采纳

页面不重定向(如果不存在),只显示没有来自其他页面的数据的代码

So I have an issue where I'm not being redirected to the 404 if the url doesn't actually exist, instead, it shows code from another page.

So I have a page called viewpost.php which typically works only if like viewpost.php?id=slug-text-of-post, but if you were to say go to bloggg.php, which doesn't exist, it would show you the viewpost page code as if you viewed it without any GET variables. So, the URL will show bloggg.php, but show the code from viewpost.php as if nothing would have been passed to it and shows this empty page with no data to fill it

This below is my .htaccess

RewriteEngine On
ErrorDocument 404 http://www.example.com/404.php
RewriteBase /
RewriteRule ^c-(.*)$ viewcat.php?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ viewpost.php?id=$1 [QSA,L]
  • 写回答

1条回答 默认 最新

  • dqx76962 2016-08-07 01:24
    关注

    Best way to achive what you want:

    RewriteEngine On
    ErrorDocument 404 http://www.example.com/404.php
    RewriteBase /
    RewriteRule ^cart/([0-9]*)$ viewcat.php?id=$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-d [NC]
    RewriteCond %{REQUEST_FILENAME} !-f [NC]
    RewriteRule ^post/([0-9]*)$ viewpost.php?id=$1 [QSA,L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#.net#的问题:End Function
  • ¥50 用AT89C52单片机设计一个温度测量与控制电路
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义
  • ¥15 嵌入式--定时器使用
  • ¥20 51单片机学习中的问题
  • ¥30 Windows Server 2016利用兩張網卡處理兩個不同網絡
  • ¥15 Python中knn问题