简体   繁体   中英

prevent page loading without extension using .htaccess

Is there any way to prevent pages from loading without extension using .htaccess file.

there is a problem with me that when i refresh/reload the page then it loads the file without extension if found.

i've only the code in .htaccess file is

RewriteEngine On
ErrorDocument 404 /index.php

Please somebody help me to figure out from this.

As I see you load and handle all links with ajax.

so you should rewrite all request to index.php which you can use this in your htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

also in your javascript file you should check the url after the page has loaded. if url contains a particular address and exist call the page by ajax or load a 404 if not exist.

Edited Try this htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

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