簡體   English   中英

.htaccess如何在地址欄中將長子目錄網址顯示為短網址?

[英].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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM