2017-05-19 32 views
1

我試圖在網站中遵循很多答案,但沒有成功。 我試圖改寫:htaccess重寫規則,使用unicode字母的參數

domain.com/articles/<author> 

要:

domain.com/articles/index.php?author=<author> 

我現在的原則是:

RewriteRule ^(\w*)$ /articles/index.php?author=$1 [B] 

與字母或數字作品,但不使用Unicode charachters像א

對於א,我收到以下錯誤:

Object not found!

The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.

Error 404

localhost Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/7.0.9

而對於

Access forbidden!

You don't have permission to access the requested object. It is either read-protected or not readable by the server.

If you think this is a server error, please contact the webmaster.

Error 403

localhost Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/7.0.9

,我需要他們。

編輯:

閱讀@ user82217評論我又試了之後正則表達式,這一次結束標誌是這樣的(*):

RewriteRule (.*) /articles/index.php?author=$1 [END] 

現在א此案正在解釋得很好。但是情況下仍然給出了同樣的錯誤(禁止訪問)

@ user82217曾建議調查日誌中。」情況下,日誌:

Cannot map GET /articles/%22 HTTP/1.1 to file

結論:

作爲@ user82217在評論中說,看來,在Windows操作系統的地址與字符被認爲是一個非法的文件服務,雖然地址不是一個fi樂此不疲。 所以我放棄了情況現在。會高興聽到,如果有一種方式來獲得解決的。

+1

你必須如此具體,你可以匹配_everything_即ie。 '(*)'? – MrWhite

+0

@ user82217:我試過了。然後我得到:「內部服務器錯誤」。 – Dorad

+0

只是測試了這種情況。它可以工作,但只能在虛擬主機非目錄上下文中使用。把你的規則放在''裏面,你會得到所有的unicode和雙引號。 – Deadooshka

回答

1
RewriteRule ^(\w*)$ /articles/index.php?author=$1 [B] 

如果你簡單地(.*)取代你的模式,那麼你將得到一個改寫環(這是你的500內部服務器錯誤),您可將該RewriteRule模式匹配一切除了斜線

RewriteRule ^([^/]*)$ /articles/index.php?author=$1 [B,L] 

不過,從你的例子目前尚不清楚你的文件位於哪裏。以上假定它位於/articles子目錄中。

或者,你可以檢查查詢字符串,只有處理指令,如果查詢字符串是空的:

RewriteCond %{QUERY_STRING} ^$ 
RewriteRule (.*) /articles/index.php?author=$1 [B,L] 

But " case still gives the same error (Access Forbidden).

UPDATE:啊,這可能是一個更根本的錯誤,可能是OS的限制(你使用Windows?)。 "字符不是有效的文件名字符。 Apache無法將其映射到一個有效的文件名,這會導致系統生成403 Forbidden。

+0

謝謝! [but:](1).htaccess文件位於/ articles目錄中。 (2)您的第一個選項導致「內部服務器錯誤 服務器遇到內部錯誤或配置錯誤,無法完成您的請求」在所有情況下:字母/數字/א/「 (3)您的第二個選項會導致:」找不到對象! 在此服務器上找不到請求的URL ...「(4)添加我省略的B標誌是」服務器錯誤! 服務器遇到內部錯誤,無法完成您的請求。 「 – Dorad

+1

爲了找到錯誤的詳細信息,您需要檢查錯誤日誌。 – MrWhite

+0

您的第一個選項是(RewriteRule([^ /] *)/ articles/index.php?author = $ 1 [B,L])日誌爲「由於可能的配置錯誤,請求超出了10個內部重定向的限制」 – Dorad

0

對於雙引號問題: 的字符不是像@MrWhite一個有效的文件名字符表示

@Deadooshka在他的評論中指出,它不能在.htaccess情況來進行 我想。他是對的。

@Deadooshka還表示,它可以在<]虛擬主機[>背景下完成的。但是,在我的開發服務器我不使用<]虛擬主機[>上下文。

因此,解決辦法是把Apache的配置文件中的全球背景下的重寫規則(在我的情況:C:\ XAMPP的\ apache的\的conf \ httpd.conf文件)是這樣的:

# <<< existing line >>> 
DocumentRoot "C:/xampp/htdocs" 
# <<< existing line >>> 
# <<<solution>>> 
RewriteEngine on 
RewriteRule /articles/(\w*)$ /articles/index.php?author=$1 [B] 
# <<<solution>>>