我想要的是通过.htaccess 重定向
http://example.com/omgitsaname
我真的想重定向,或者更好的是,保持不变,但从获得信息
http://example.com/product?id=omgitsaname
如果您想在浏览器中使用这些类型的URL
http://example.com/omgitsaname
您可以这样做,并确保URI不是真正的目录或文件。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /product?id=$1 [NC,L]
以下是如何在Apache
中通过.htaccess
使用Rewrite Rules
RewriteEngine On
RewriteRule ^product/?$ do/something/here [NC,L]
RewriteRule ^([a-z]+)/?$ product?id=$1 [NC,L]
确保mod_rewrite
模块(或等效模块)已启用。还要添加以下规则:AllowOverride all
(或等效规则)以允许.htaccess
工作。
注意:根据需要修改正则表达式。编辑:感谢@4sha修复了重定向循环。