PHP .htaccess 重定向到一个文件夹


PHP .htaccess redirect to a folder

我有PHP .htaccess来管理用户配置文件,如下所示:

http://example.com/user?=blabla

要成为

http://example.com/blabla

这是 .htaccess

Options -Multiviews
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1'.php [L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?user=$1
RewriteRule ^([a-zA-Z0-9_-]+)$ post.php?user=$1
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/home/.*$ index.php [QSA]

现在我想做成这样:

http://example.com/blabla/post/

帖子是一个文件夹。

我尝试在根文件夹中发布文件夹帖子,但仍然错误。但是当我尝试键入此 URL 时,http://example.com/user/post 它运行正常。

我想要的是用户可以打开http://example.com/blabla/post/

您可以使用此规则:

Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^home/?$ index.php [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.+?)/?$ $1'.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ user.php?user=$1 [L,QSA]