成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁技術文章
文章詳情頁

javascript - htaccess rewrite 的問題

瀏覽:70日期:2023-08-22 08:28:11

問題描述

我有個thinkphp開發的網站,企用了mod rewrite

<IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfModule>

thinkphp 和程序運行正常,現在我的需求是,我在網站根目錄的hot目錄下,放了一個vue開發的小程序,并開啟了histroy路由模式,按照開發文檔說明 為了讓所有的路徑都可以被服務器識別,也要通過RewriteRule 把所有的訪問 Rewrite到 index.hml上

也就是說要把http://wwww.xxx.com/hot/item/1000 這樣的url 解析到/hot/index.html上,其它還是用thinkphp來控制,試過了好多配置 都不行,本人對.htaccess文件命令不熟悉,所以希望大家給個方案

回復一樓的內容,我也貼一下這里 vue 運行也是正常的,在開啟histroy 模式下,你進入http://www.xxx.com/hot可以正常運行,點擊各個鏈接也是可以正常跳轉,因為html5的histroy模式只是在瀏覽器段改變了url地址欄,并沒有向server請求數據,但是當用戶直接用 http://www.xxx.com/hot/item/1000 這樣的url來訪問的時個,由于server上并沒有這個文件 所以不會正常返回,但是通過apache的htaaccess文件可以把用戶訪問不存在的文件跳轉到指定的文件上,就如我上面貼的thinkphp下的配置文件就是起這個作用,我現在的要求是把在/hot目錄下的請求 不要轉發給thinkphp來執行,而是轉發個/hot/index.html來處理。

我嘗試如下

<IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_URI} ^/(hot|hot/.*)$ RewriteRule ^/hot/index.html$ - [L] RewriteRule ^(hot|hot/.*)$ hot/index.html$ [L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f #RewriteRule ^hot/(.*)$ hot/index.html$ #RewriteRule '.?' '-' [S=1] #RewriteRule ^/(hot|hot/.*)$ /hot/index.html$ [L] RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfModule>

但是不起作用,不知道為什么?

問題解答

回答1:

對 thinkphp 不了解,可以看一下 thinkphp 的路由配置可否指定某一個目錄不同的路由方案

如果不行可能要用 nginx 了

回答2:

解決了,原來的我想法是對的,一開始老是被解析到主目錄的index.php原來是我的引用資源路徑的問題貼出有效 配置

<IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_URI} ^/(hot|hot/.*)$ RewriteRule ^/hot/index.html$ - [L,NC] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(hot|hot/.*)$ hot/index.html [L] RewriteCond %{REQUEST_URI} !^/(hot|hot/.*)$ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfModule>

測試地址: http://www.wx2share.com/hot/如果不做url rewrite 直接通過 以上網址進入,一切功能也是正常的,

但是如果通過如下網址進入http://www.wx2share.com/hot/i...就會返回 404,但是做了 url rewrite 就可以正常訪問了

標簽: JavaScript
相關文章: