2017-08-19 117 views
0
<Files ~ (\.php)> 
Options +SymLinksIfOwnerMatch 
</Files> 
AddDefaultCharset utf-8 
RewriteEngine on 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^.*$ index.php [NC,L] 
RewriteRule ^([A-Za-z0-9-]+)/([0-9]+)/([0-9]+)$ index.php?lang=$1&menu=$2&submenu=$3 [L] 

源URL:example.com/index.php?lang=de &菜單= 1項&子菜單= 0 新網址:example.com/de/1/0htaccesc重寫規則不起作用

載入新網址主頁,但需要另一個頁面

+0

問題是什麼究竟,什麼是你所面臨的問題?目前我們根據當前的信息無法回答任何問題。 –

+0

問題:爲什麼網址「example.com/de/1/0」不喜歡工作URL「example.com/index.php?lang=de&menu=1&submenu=0」 – Max

+0

此頁上的「example.com/index.php ?lang = de&menu = 1&submenu = 0「我有」關於公司「,但是此網址爲」example.com/de/1/0「加載」主頁「。在重寫URL我也需要「關於公司」 – Max

回答

0
<Files ~ (\.php)> 
Options +SymLinksIfOwnerMatch 
</Files> 
AddDefaultCharset utf-8 
RewriteEngine on 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^.*$ index.php [NC,L] 
RewriteRule ^([A-Za-z0-9-]+)/([0-9]+)/([0-9]+)$ index.php?lang=$1&menu=$2&submenu=$3 [L] 

如果按照這個,你告訴Apache將採取一切,這是不是一個文件或文件系統的目錄,並重寫的index.php。

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^.*$ index.php [NC,L] 

所以這就是它在做什麼。

爲了使這個做你想要什麼,你必須做出這樣的:

<Files ~ (\.php)> 
Options +SymLinksIfOwnerMatch 
</Files> 
AddDefaultCharset utf-8 
RewriteEngine on 
RewriteBase/
# if file/director does not exist, and if it matches the pattern 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([A-Za-z0-9-]+)/([0-9]+)/([0-9]+)$ index.php?lang=$1&menu=$2&submenu=$3 [QSA,L] 
# then if it did not match the pattern, send it to index.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^.*$ index.php [NC,L] 

請注意,您沒有提供足夠的信息來了解你實際上是試圖實現。但我的猜測是這樣的。我還假設你想將值追加到index.php(QSA)的查詢字符串中,這通常是你想要的。

但它不是真的有可能進一步猜測,直到您指定的內容的所有網址都應該做的。

注意,通過匹配任何不是文件/目錄,並且不經進一步的參數作爲最後的命令的index.php(L),即結束請求處理重寫它,它永遠不會擊中的第二種情況。

+0

謝謝,現在我明白了,什麼是錯的 – Max