[英]URL rewriting and URL redirection
So I have the following rule in my htaccess : 所以我在htaccess中有以下规则:
RewriteEngine on
RewriteBase /blog/
RewriteRule ^post/ post.php [L]
This gives me access to localhost/blog/post.php
via localhost/blog/post/
这使我可以通过
localhost/blog/post/
访问localhost/blog/post.php
Now, when I'm directly typing localhost/blog/post.php
it does not redirect me to localhost/blog/post/
现在,当我直接输入
localhost/blog/post.php
它不会将我重定向到localhost/blog/post/
Is there a way to redirect to localhost/blog/post/
in .htaccess or should I do that in php code ? 有没有一种方法可以重定向到.htaccess中的
localhost/blog/post/
,还是应该在php代码中这样做?
You need an additional rule to redirect /post.php to /post 您需要一条附加规则才能将/post.php重定向到/ post
RewriteEngine on
RewriteBase /blog/
#1)--redirect /post.php to /post--#
RewriteCond %{THE_REQUEST} /post\.php
RewriteRule ^ /blog/post/ [NC,L,R]
#2)--rewrite /post to /post.php--#
RewriteRule ^post/ post.php [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.