简体   繁体   English

.htaccess用GET参数重写

[英].htaccess rewriting with GET parameter

I want to set up .htaccess file for rewrting url like example.com/33 to example.com?id=33 (example.com/index.php?id=33) and example.com/Test to example.com?name=Test (example.com/index.php?name=Test) 我想设置.htaccess文件以将网址(例如example.com/33)改写为example.com?id=33(example.com/index.php?id=33),并将example.com/Test改写为example.com?name =测试(example.com/index.php?name=测试)

My htaccess file: 我的htaccess文件:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ /index.php?id=$1 [QSA,L]

But when I goto url example.com/33 it will redirect me to index.php, but id parameter doesn't exist. 但是当我转到网址example.com/33时,它将重定向到index.php,但id参数不存在。 Where can be the problem please? 请问哪里有问题?

Try this 尝试这个

RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?id=$1 [L]

Have 2 rewrite rules, one for digits (id) and another for name parameter: 有2条重写规则,一条用于数字(id),另一条用于name参数:

RewriteEngine On

# ignore all existing files and directories for rewriting     
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

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

RewriteRule ^(\w+)/?$ index.php?name=$1 [QSA,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM