Bashar Bashar - 3 years ago 112
Apache Configuration Question

.htaccess rules for accessing only index.php and work jQuery post method

I am trying to figure out the rules about three conditions

  1. No one can access any php files and directories except index.php

  2. Hide get variables from URL

  3. jQuery post method should work

Few examples of my website URL are

    I want it to be like

    I want it to be like

    I want it to be like

And I have jQuery post request like this

$.post('config/post-ajax.php', "zilla="+el.val()).success(function(data) {
var data = $.parseJSON(data);
for (var i = 0; i < data.length; i++) {
$("#thana").append("<option class=\"rm1\" value="+data[i]+">"+data[i]+"</option>");


Answer Source

Finally I have made it by myself. Here are the working rules

RewriteEngine on

#If it is not POST request

#And if URL doesn't indicate index.php or /admin/index.php
RewriteCond %{REQUEST_URI} !^(/index\.php|/admin/index\.php)$ [NC] 

#And if URL indicates .php file(extension)
RewriteCond %{REQUEST_URI} \.php$ [NC,OR]

#OR if URL indicates a directory called /config or /uploads
RewriteCond %{REQUEST_URI} ^(/config/|/uploads/)$ [NC] 

#Then redirects any link to 404 not found page
RewriteRule ^(.*)$ - [R=404,L]

#Rest of the conditions are for URL change upto 3 GET variables    
RewriteRule ^([^/.]+)/?$ index.php?var1=$1 [QSA]
RewriteRule ^([^/.]+)/([^/.]+)/?$ index.php?var1=$1&var2=$2 [QSA]  
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ index.php?var1=$1&var2=$2&var3=$3 [QSA]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download