Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.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
Php 如何使用OR运算符编写url重写?_Php_.htaccess - Fatal编程技术网

Php 如何使用OR运算符编写url重写?

Php 如何使用OR运算符编写url重写?,php,.htaccess,Php,.htaccess,这是站点的文件结构: site_one_folder index.php 在site_one_文件夹中有一个文件: controller.php 我想给你写一条重写规则 如果人们搜索www.mysiteurl/index.php或www.mysiteurl或www.mysiteurl/,它将运行index.php 如果人们搜索而不是index.php: 示例:我将搜索 www.mysiteurl/something.php 然后浏览器将显示上面的url,但内容必须是 `www.mysiteu

这是站点的文件结构:

site_one_folder
index.php
在site_one_文件夹中有一个文件:

controller.php
我想给你写一条重写规则

  • 如果人们搜索www.mysiteurl/index.php或www.mysiteurl或www.mysiteurl/,它将运行index.php
  • 如果人们搜索而不是index.php: 示例:我将搜索
  • www.mysiteurl/something.php

    然后浏览器将显示上面的url,但内容必须是

    `www.mysiteurl/site_one_folder/controller.php?para=something`
    

    注意:para=搜索的文件名不包括(.php)

    尝试将其添加到根文件夹中的htaccess文件中(其中
    index.php
    为):


    确保已启用mod_rewrite。直接访问index.php的第一个条件。第二,避免无限重定向

    RewriteEngine on
    
    RewriteCond %{REQUEST_URI} !^/index.php$
    RewriteCond %{REQUEST_URI} !^/site_one_folder/controller.php$
    RewriteRule ^(.+)\.php$ site_one_folder/controller.php?para=$1 [L]
    

    我试过这个。但它不适用于index.php。对于index.php,它显示/site\u one\u folder/controller.php?第=index@user1712287index.php文件是否存在?这两个条件确保对存在的文件或目录的任何请求都将被排除。L、QSA和NC、L之间有什么区别吗?@user1712287这些标志都不会影响
    index.php
    是否被执行。NC=无大小写,QSA=查询字符串追加。它不工作。尝试此操作将创建500个内部服务器错误。请在htacces中仅保留此行,然后重试。我复制你的文件夹结构。它起作用了
    RewriteEngine on
    
    RewriteCond %{REQUEST_URI} !^/index.php$
    RewriteCond %{REQUEST_URI} !^/site_one_folder/controller.php$
    RewriteRule ^(.+)\.php$ site_one_folder/controller.php?para=$1 [L]