如果url有参数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]
使用this.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文件中尝试以下配置,我只是测试一下,然后在我的env上玩得很开心。
//htaccess file content
RewriteEngine On
RewriteRule ^('w+).html$ /index.php?id=$1 [L]