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]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)