簡體   English   中英

如何使用.htaccess重定向重寫規則鏈接

[英]how to redirect rewrite rule link using .htaccess

我如何創建重寫規則以使用.htaccess獲得漂亮的鏈接。 例如,我有一個這樣的鏈接:

http://localhost/piratefiles/view.php?idp=2&cat=Animation&pst=In-this-Corner-of-the-World-(Kono-Sekai-no-Katasumi-ni)/

我想使我的網址像這樣,我不需要鏈接中的():等。

http://localhost/piratefiles/view/2/in-this-corner-of-the-world-kono-sekai-no-katsumi-ni

要不就

http://localhost/piratefiles/view/2/

我的密碼

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} "^([^/]*?)(?:/|%20)+([^/]+?(?:/|%20)+.*)$"
RewriteRule ^ %{REQUEST_URI}?%1-%2 [N,NE]

RewriteCond %{QUERY_STRING} "^([^/]*?)(?:/|%20)+([^/]+?)/?$"
RewriteRule ^ %{REQUEST_URI}?%1-%2/ [L,R=302,NE]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/$    index.php    [L]

#Your section
RewriteRule ^view/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$    view.php?idp=$1&cat=$2&pst=$3   [NC,L]

ErrorDocument 404 http://www.akshadainfosystem.com/

RewriteRule ^([^\.]+)$ $1.php [NC,L]

將此代碼放入您的.htaccess文件中,然后清除所有cookie

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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