簡體   English   中英

使用htaccess將網址www.xyz.com/index.php?id=xyz重寫為www.xyz.com/xyz

[英]rewrite url www.xyz.com/index.php?id=xyz to www.xyz.com/xyz using htaccess

如果網址具有參數id=xyz我想包含項目詳細信息details.php

改寫

url www.example.com/index.php?id=xyz 

www.example.com/xyz.html 

使用htaccess

我正在使用的htaccess

RewriteEngine On
RewriteBase /

RewriteRule ^([^.]+)\.html$ index.php?id=$1 [L,QSA,NC]
RewriteCond %{THE_REQUEST} \s/index\.php\?id=([_0-9a-zA-Z-]+)\s [NC]
RewriteRule ^%1? [R=301,L]
RewriteRule ^([_0-9a-zA-Z-]+)$ /index.php?id=$1 [L]

RewriteCond %{THE_REQUEST} \s/index\.php\?id=([_0-9a-zA-Z-]+)\s [NC]
RewriteRule ^ %1.html? [R=301,L]
RewriteRule ^([_0-9a-zA-Z-]+?)(?:\.html)?$ /index.php?id=$1 [NC,L]

工作完美

您可以在DOCUMENT_ROOT/.htaccess文件中使用以下代碼:

RewriteEngine On
RewriteBase /

RewriteRule ^([^.]+)\.html$ index.php?id=$1 [L,QSA,NC]

使用此.htaccess重寫:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^.]+)\.html$ index.php?id=$1 [L,QSA,NC]
</IfModule>

確保已啟用mod_rewrite (如果可用,請在PHP中使用phpinfo()apache_get_modules()

請嘗試在您的www.example.com/.htaccess文件中進行以下配置,我只是對其進行測試,並在我的環境中進行娛樂。

//htaccess file content
RewriteEngine On  
RewriteRule ^(\w+).html$ /index.php?id=$1 [L]

暫無
暫無

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

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