Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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 htaccess使用参数重写URL,同时保留索引页_Php_.htaccess_Url Rewriting - Fatal编程技术网

PHP htaccess使用参数重写URL,同时保留索引页

PHP htaccess使用参数重写URL,同时保留索引页,php,.htaccess,url-rewriting,Php,.htaccess,Url Rewriting,我一直在寻找解决方案,但找不到 问题如下: 我的网站上有一个目录,例如domain.com/directory/。我制作了一个带有自定义URL的自定义CMS,这些URL添加在目录/之后,例如domain.com/directory/example page。我使用htaccess将directory/post.php?URL=xxx的URL重写为directory/xxx 问题是它不起作用,因为我有一个index.php文件要继续使用 我是这样做的: RewriteRule ^directory

我一直在寻找解决方案,但找不到

问题如下:

我的网站上有一个目录,例如
domain.com/directory/
。我制作了一个带有自定义URL的自定义CMS,这些URL添加在
目录/
之后,例如
domain.com/directory/example page
。我使用htaccess将
directory/post.php?URL=xxx
的URL重写为
directory/xxx

问题是它不起作用,因为我有一个index.php文件要继续使用

我是这样做的:

RewriteRule ^directory/subdirectory/(.*)$ directory/post.php?url=$1 [NC,L] [QSA]
但是我不想在URL中使用额外的子目录

那么,在使用index.php的同时,如何将
directory/post.php?url=xxx
重写为
directory/xxx

我知道这听起来很复杂,但我已经找了好几天的解决办法了


提前谢谢

不确定我是否正确理解了这个问题,但这应该是可行的

RewriteRule    ^directory/?$    /index.php?url=test

您可以使用以下规则

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^directory/([^/.]+)/?$ /directory/post.php?url=$1 [QSA,L]

谢谢你的建议,但问题是我想在访问domain.com/directory/时像往常一样查看index.php页面,但我也想将directory/post.php?url=xxx重定向到directory/xxx@SenneVandenputte这应该是可行的,但您需要在另一个规则之前添加它作为附加规则。如果
directory/
之后没有任何内容,并且需要一个
[L]
标志来告诉它停止处理进一步的规则,则此规则将传递到index.php。如果在
目录/
之后有任何内容,此规则将失败,下一个规则将被处理。@JonathanKuhn谢谢,但它仍然不是我想要的。我会给你我想要的
mydomain.com/guides/
包含我的网站的一部分,其中包含特定主题的指南和信息。访问此URL时,会显示索引页,这是正常的。还有其他文件,如
guides/buying guides
guides/training guides
,所有这些文件都重写为remove.php。现在,我有一个post.php,它使用要重写的参数。因此,我需要
domain.com/guides/post.php?url=example
成为
domain.com/guides/example
,同时保持我的其他文件也可访问。您的htaccess是否位于根目录下?@starkeen是的