我是htaccess编码的新手。 我有一个链接到我的培训师资料页面,如下所示。
trainer-profile?usr=SamJohn&id=MTAy
使用ht访问隐藏.php标记。我想将此网址结构更新为
trainer-profile/SamJohn/MTAy
尝试了以下代码,但它没有工作
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+trainer-profile\.php\?usr=([a-z0-9]+)&id=([a-z0-9]+) [NC]
RewriteRule ^ %1/%2/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9]+)/([a-z0-9]+)/?$ /trainer-profile.php?usr=$1&id=$2 [L,NC]
在网址[
trainer-profile.php?usr = SamJohn& id = MTAy ]
中显示 .php 时,此htaccess代码运行良好,但重定向到另一个网址,显示404错误
/OscarKemjika/MTAy/?usr=OscarKemjika&id=MTAy
我使用以下ht访问
**Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^forums/ - [L,NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [L,R=301]
RewriteCond %{QUERY_STRING} usr=([^&]*)&id=([^&]*)
RewriteRule ^trainer-profile$ trainer-profile/%1/%2/? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^trainer-profile/([a-z0-9]+)/([a-z0-9]+)/?$ trainer-profile.php?usr=$1&id=$2 [L,NC]**
应用htaccess代码之前的URL结构是
http://mydomainname.com/trainer-profile?usr=JohnSam&id=MTAx
提前致谢。
答案 0 :(得分:-1)
尝试更改
[a-z0-9]
到
[a-zA-Z0-9]
案例敏感的A-Z