[英].htaccess rewriterule help,
我似乎無法弄清楚如何通過我的.htaccess來實現這些條件
http://example.com/index.php?page=about
to
http://example.com/about
同時
http://example.com/index.php?process=login
to
http://example.com/p/login
我自己嘗試過這樣做,但是我不知道如何同時進行這兩個操作。
使用Apache
最簡單的情況
URL重寫的最簡單情況是重命名單個靜態Web頁面,這比上面的B&Q示例要容易得多。 要使用Apache的URL重寫功能,您將需要在網站的文檔根目錄(或較不常見的子目錄)中創建或編輯.htaccess文件。
RewriteEngine On
RewriteRule about index.php?page=about
RewriteRule login index.php?process=login
使用常規表達
在URL重寫中,您只需要匹配URL的路徑,而不包括域名或第一個斜杠
RewriteEngine On
RewriteRule ^about/?$ index.php?page=about [NC]
RewriteRule ^login/?$ index.php?process=login [NC]
您也可以這樣做
example.com/index.php?page=about
至
example.com/about.html 或 example.com/about
使用這個規則
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /index.php?page=$1 [L]
要么
RewriteEngine On RewriteRule ^([^/]*)$ /index.php?page=$1 [L]
這是一些有用的鏈接
干杯!
穆達薩里·阿里
將此代碼放在您的DOCUMENT_ROOT/.htaccess
文件中:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^p/([^/]+)/?$ /index.php?process=$1 [L,QSA]
RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L,QSA]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.