[英].htaccess how to display long sub-directory urls as short urls in address bar?
I've been trying to solve this problem for a couple of days now. 我已经尝试解决这一问题了几天了。 My root folder is https://www.example.com , I have many articles on it but in different folders and sub-folders for better organizing.
我的根文件夹是https://www.example.com ,上面有很多文章,但它们位于不同的文件夹和子文件夹中,以便更好地组织。
The problem is that I want links to look better and not like: 问题是我希望链接看起来更好,而不是像这样:
> https://www.example.com/reviews/review_1/index.html
/review_2/index.html
/review_3/index.html
or 要么
https://www.example.com/articles/blog/content_1/index.html
/content_2/index.html
/content_3/index.html
but instead, I want all folders under "reviews and articles" to appear like root/dirs: 但相反,我希望“评论和文章”下的所有文件夹都显示为root / dirs:
https://www.example.com/review_1/index.html
https://www.example.com/content_1/index.html
...so is it possible to exclude ../reviews/
or ../articles/blog/
folder somehow, but to have the same directory structure and also not to have duplicate content, indexes or duplicate DIRs? ...因此可以以某种方式排除
../reviews/
或../articles/blog/
文件夹,但具有相同的目录结构,并且也没有重复的内容,索引或重复的DIR?
EDIT / I found the solution: 编辑/我找到了解决方案:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteRule ^review_1/(.*) reviews/review_1/$1
This code will redirect from folder reviews/review_1/
to unexisting folder review_1
on root and copy all content from reviews/review_1/
to review_1
. 此代码将从文件夹
reviews/review_1/
重定向到根目录下不存在的文件夹review_1
,并将所有内容从reviews/review_1/
复制到review_1
。
just create an associative arrow specifying the mapping between url's and what they mean under the hood, for example I use in php like this- 只需创建一个关联箭头,指定url与引擎盖之间的对应关系即可,例如,我在php中使用的代码如下:
$route = array(
array(
'url' => 'review_1/index.html',
'map_to' => '/articles/blog/reviews/index.html'
),
array(
)
);
or better version like implementing simple routing- 或更好的版本,例如实施简单的路由-
$route = array( array( 'url' => '/review/', 'controller' => 'controller_class', 'action' => 'model_class' ), array( ) );
better proceed with second process.. do some research in implementing routing yourself or use basic framework. 最好继续进行第二个过程..在自己实施路由或使用基本框架方面进行一些研究。 Hope it helps.
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.