htaccess 重写任何文件夹但不重写任何文件

htaccess rewrite any folder but not any file

我有这样的 URL 指向文件夹:

1) https://try.com/documentation/license/
2) https://try.com/documentation/license

我想重写两个指向 PHP/pages。php

我试过这个:

RewriteRule ^(.*)/$ PHP/pages.php [NC]

这适用于案例 #1 但不适用于案例 #2。

我也试过这个:

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule PHP/pages.php [L]

这根本行不通。

案例是目录名是这样的:

/pages/documentation/license/

如何操作?

将您的 .htaccess 文件放入您的页面 directory/folder 并在其中放置以下规则。另外,请在测试您的网址之前清除浏览器的缓存。

RewriteEngine ON
RewriteRule ^documentation/license/?$ PHP/pages.php [NC,L]

对于通用重写:您可以使用以下内容。

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.*)/?$ PHP/pages.php [NC,L]