简体   繁体   English

PHP htaccess在保留索引页的同时用参数重写URL

[英]PHP htaccess rewrite URL with parameters while keeping index page

I have been looking for a solution, but can't find one. 我一直在寻找解决方案,但找不到。

The problem is the following: 问题如下:

I have a directory on my website, for example domain.com/directory/ . 我的网站上有一个目录,例如domain.com/directory/ I made a custom CMS with custom URL's that are added after directory/ , like for example domain.com/directory/example-page . 我制作了一个具有自定义URL的自定义CMS,该URL添加到directory/ ,例如domain.com/directory/example-page I used htaccess to rewrite the URL of directory/post.php?url=xxx to directory/xxx 我使用htaccess将directory/post.php?url=xxx的URL重写为directory/xxx

The problem is that it is not working, since I have an index.php file I want to keep using. 问题是它不起作用,因为我有一个想要继续使用的index.php文件。

I fixed it by doing it like this: 我通过这样做来解决它:

RewriteRule ^directory/subdirectory/(.*)$ directory/post.php?url=$1 [NC,L] [QSA]

But I don't want to use the extra subdirectory in the URL. 但是我不想在URL中使用额外的子目录。

So, how can I rewrite directory/post.php?url=xxx to directory/xxx while keeping directory/ working with index.php? 那么,如何在保持directory/使用index.php的同时将directory/ directory/post.php?url=xxx重写为directory/xxx

I know it sounds complicated, but I have been looking for a solution for days. 我知道这听起来很复杂,但是几天来我一直在寻找解决方案。

Thanks in advance! 提前致谢!

不知道我是否正确理解了这个问题,但这应该可以工作。

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

You can use the following rule 您可以使用以下规则

RewriteEngine on

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM