Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache .htaccess仅用于访问index.php和work jQuery post方法的规则_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache .htaccess仅用于访问index.php和work jQuery post方法的规则

Apache .htaccess仅用于访问index.php和work jQuery post方法的规则,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我试图找出关于三个条件的规则 除了index.php之外,没有人可以访问任何php文件和目录 隐藏从URL获取变量 jQuery post方法应该有效 我的网站URL的几个例子是 example.com/?page=搜索 我希望它像example.com/search example.com/?page=username&profile=overview 我希望它像example.com/username/overview example.com/?page=result&pn=1 我希望它像

我试图找出关于三个条件的规则

  • 除了index.php之外,没有人可以访问任何php文件和目录
  • 隐藏从URL获取变量
  • jQuery post方法应该有效
  • 我的网站URL的几个例子是

    • example.com/?page=搜索 我希望它像example.com/search

    • example.com/?page=username&profile=overview 我希望它像example.com/username/overview

    • example.com/?page=result&pn=1 我希望它像example.com/result/1

    我有这样的jquerypost请求

    $.post('config/post ajax.php',“zilla=“+el.val()).success(函数(数据)){
    var data=$.parseJSON(数据);
    $('.rm1').remove();
    对于(变量i=0;i});这应该像您所表达的那样:

    RewriteEngine On
    
    ## Show 404 for all .php files except index.php
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{REQUEST_URI} !^/?index\.php$ [NC]
    RewriteCond %{REQUEST_URI} \.php$ [NC]
    RewriteRule ^(.*)$ - [R=404,L]
    
    ## Redirect 301 with one query parameter
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{QUERY_STRING} ^page=([^&]*)$ [NC]
    RewriteRule ^(.*)$ /%1? [R=301,L]
    
    ## Redirect 301 with two query parameters
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{QUERY_STRING} ^page=([^&]*)&[^=]*=([^&]*)$ [NC]
    RewriteRule ^(.*)$ /%1/%2? [R=301,L]
    
    ## Redirect 301 with three query parameters
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{QUERY_STRING} ^page=([^&]*)&[^=]*=([^&]*)&[^=]*=([^&]*)$ [NC]
    RewriteRule ^(.*)$ /%1/%2/%3? [R=301,L]
    
    ## Start: rewrite all to index.php
    RewriteBase /
    RewriteCond %{REQUEST_METHOD} !POST
    # except all real files like images, css, js, etc.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* index.php [L]
    
  • 所有重写不适用于POST请求
  • 请求一个.php文件将输出404页面
  • 如果查询Sting以页面=开头,它将被重定向(最多3个参数)
  • 除非是真实文件(图像、css、js等),否则将始终调用index.php文件

  • 我终于自己做了。以下是工作规则

    RewriteEngine on
    
    #If it is not POST request
    RewriteCond %{REQUEST_METHOD} !POST
    
    #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]
    

    我得到了预期的URL,但它只显示我在example.com/之后放置的任何内容的主页。我使用index.php中的require_once根据GET参数加载网页主体。您的php必须解释(路由)新类型的URL。$\u GET变量将为空,但您将拥有带有例如“/username/overview”的$\u SERVER[“REQUEST\u URI”]。现在,您必须反转逻辑以获得预期的查询参数。这不是一个容易的工作,但如果你想只有SEF网址的唯一途径。对你的申请附加备注。如果新的SEF URL正常工作,您还应该在页面上输出新的URL。不要执行href=“/?page=search”但href=“/search”,否则您的网站上总是会有重定向。