我们有一个重写规则设置来将/spaces/test.php映射到/areas/spaces/test/,如下所示:
RewriteRule ^areas/spaces/?$ spaces/$1.php这样,URL就会被不同的映射,但是底层逻辑/代码仍然是spaces/test.php。
因此,如果我们现在访问areas/spaces/test/或spaces/test.php,它们都能工作。但是..。我想要一个301号重定向spaces/test.php > areas/spaces/test/。
这个是可能的吗?
发布于 2017-11-07 14:50:55
您可以使用以下重写规则来完成您希望的两件事。
RewriteRule ^spaces/([^/.]+).php$ /areas/spaces/$1/ [QSA,R=301,L]
RewriteRule ^areas/spaces/?$ spaces/$1.php [L]我将带领你完成我添加的第一行:
^spaces/([^/.]+)\.php$的请求/areas/spaces/$1/R=301。QSA告诉Apache附加任何传递到新位置的查询字符串。L告诉Apache在匹配时停止在该行上重写,这样就会发生重定向并停止重写。在对适当位置的下一个请求中,第二行将与您想要的匹配,因此在内部是处理请求的.php文件。另见: docs
发布于 2017-11-08 14:34:08
这应该可以做到:
RewriteRule ^areas/spaces/([^/.]+)/$ spaces/$1.php [L,E=CLEAN_URL:1]
RewriteCond %{ENV:REDIRECT_CLEAN_URL} !1
RewriteRule ^spaces/([^/.]+).php$ areas/spaces/$1/ [R=301,L]https://stackoverflow.com/questions/47160658
复制相似问题