I have a problem in RewriteRule htaccess: example: my php file is main.php we need to when user trying to www.mysite.com/hello , then show www.mysite.com/main.php for this expamle we have below code in .htacces:
# BEGIN Htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^hello/*$ main.php
but in this code if user can open www.mysite.com/hello and www.mysite.com/main.php
I need if user trying www.mysite.com/main.php then show error 404 but if trying for www.mysite.com/hello view content of main.php
thank you;)
You need to match against the actual request here:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /main\.php
RewriteRule ^ - [L,R=404]
You can add that just under RewriteEngine On
if you want. The other way of dealing with this is to maybe check for $_SERVER['REQUEST_URI']
in your main.php script and if it's /main.php
, instead of serving content, return a 404 response.
You can't 404 main.php neither can you 301 it to /hello as it'll go into infinite loop. You'll have to check the url in main.php and if it is different than hello, redirect it to /hello
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.