![](/img/trans.png)
[英]Apache .htaccess rewrite rule to redirect urls from sub-directory to parent directory
[英].htaccess how to display long sub-directory urls as short urls in address bar?
我已经尝试解决这一问题了几天了。 我的根文件夹是https://www.example.com ,上面有很多文章,但它们位于不同的文件夹和子文件夹中,以便更好地组织。
问题是我希望链接看起来更好,而不是像这样:
> https://www.example.com/reviews/review_1/index.html
/review_2/index.html
/review_3/index.html
要么
https://www.example.com/articles/blog/content_1/index.html
/content_2/index.html
/content_3/index.html
但相反,我希望“评论和文章”下的所有文件夹都显示为root / dirs:
https://www.example.com/review_1/index.html
https://www.example.com/content_1/index.html
...因此可以以某种方式排除../reviews/
或../articles/blog/
文件夹,但具有相同的目录结构,并且也没有重复的内容,索引或重复的DIR?
编辑/我找到了解决方案:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteRule ^review_1/(.*) reviews/review_1/$1
此代码将从文件夹reviews/review_1/
重定向到根目录下不存在的文件夹review_1
,并将所有内容从reviews/review_1/
复制到review_1
。
只需创建一个关联箭头,指定url与引擎盖之间的对应关系即可,例如,我在php中使用的代码如下:
$route = array(
array(
'url' => 'review_1/index.html',
'map_to' => '/articles/blog/reviews/index.html'
),
array(
)
);
或更好的版本,例如实施简单的路由-
$route = array( array( 'url' => '/review/', 'controller' => 'controller_class', 'action' => 'model_class' ), array( ) );
最好继续进行第二个过程..在自己实施路由或使用基本框架方面进行一些研究。 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.