![](/img/trans.png)
[英]How to convert “www.xyx.com/index.php?great=find” to “www.xyz.com” only?
[英]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.