【发布时间】:2016-01-18 15:03:11
【问题描述】:
下面的代码将我们网站上 /profiles/ 目录中的所有 URL 从 example.com/profiles/name/ 重写为 example.com/name/,但我们还想删除尾部斜杠以进一步简化生成的 URL 到更漂亮的 example.com/name -- 就像在现代社交媒体上一样。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /profiles/$1 [NC,L]
如何才能做到(并安全地做到)?我们在 Stumble Upon 上看到了几种解决方案,如果组合起来可能可行,但我们网站上的所有配置文件目前都有自己的物理目录,而不是通过脚本即时组装。
更新:@jon-lin 在How to access directory's index.php without a trailing slash AND not get 301 redirect 为类似情况提供了解决方案——但我们不知道如何将其应用于我们的解决方案(如上所述)。
【问题讨论】:
标签: apache .htaccess mod-rewrite trailing-slash vanity-url