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