我有一個路徑/ posts/Bob/53c6acf8963e3/如何在我的.htaccess文件中創建我的重寫規則?
其中posts與一個名爲post.php的文件相關。 Bob是用戶名,53c6acf8963e3是唯一的字符串。
所以它應該涉及到類似post.php?用戶名=鮑勃& unique_string = 53c6acf8963e3 但我不想使用它,因爲它看起來不好看啊哈。
我可以使用什麼樣的htaccess規則?
我有一個路徑/ posts/Bob/53c6acf8963e3/如何在我的.htaccess文件中創建我的重寫規則?
其中posts與一個名爲post.php的文件相關。 Bob是用戶名,53c6acf8963e3是唯一的字符串。
所以它應該涉及到類似post.php?用戶名=鮑勃& unique_string = 53c6acf8963e3 但我不想使用它,因爲它看起來不好看啊哈。
我可以使用什麼樣的htaccess規則?
您可以使用此規則:
RewriteEngine on
RewriteRule ^([\w]+)/([\w]+)/([\w]+)/?$ $1.php?username=$2&unique_string=$3 [QSA,L]
查看更多關於QSA flag here。
RewriteEngine on
RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z0-9]+)/?$ $1.php?username=$2&unique_string=$3 [NC,L]
爲什麼反對票? –
請包括您嘗試過的以及具體出錯的地方。 – showdev
(這是+1和兩個-1) –