简体   繁体   中英

Content isn't hidden on url-rewrite url, but is on normal url

I am using this code to prevent a <div> element from being displayed on the page example.php:

<?php if($_SERVER["SCRIPT_NAME"] !== '/example.php') { ?>
<div>Example</div>
<?php } ?>

Using this code in .htaccess , I can change the page name from example.php to example :

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

When I visit http://website.com/example.php , the <div> element does not show - but when I visit http://website.com/example , it does - how can I stop this?

use strpos() :-

<?php if(strpos($_SERVER["SCRIPT_NAME"], 'example') === false) { ?>
   <div>Example</div>
<?php } ?>

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