简体   繁体   中英

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/ . I made a custom CMS with custom URL's that are added after directory/ , like for example domain.com/directory/example-page . I used htaccess to rewrite the URL of directory/post.php?url=xxx to directory/xxx

The problem is that it is not working, since I have an index.php file I want to keep using.

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.

So, how can I rewrite directory/post.php?url=xxx to directory/xxx while keeping directory/ working with index.php?

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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