Php Htaccess-更新URL格式
Iam不熟悉htaccess编码。 我有一个指向我的培训师个人资料页面的链接,如下所示Php Htaccess-更新URL格式,php,.htaccess,Php,.htaccess,Iam不熟悉htaccess编码。 我有一个指向我的培训师个人资料页面的链接,如下所示 trainer-profile?usr=SamJohn&id=MTAy 使用ht访问隐藏.php标记。我想将此url结构更新为 trainer-profile/SamJohn/MTAy 尝试了以下代码,但无效 RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+trainer-profile\.php\?u
trainer-profile?usr=SamJohn&id=MTAy
使用ht访问隐藏.php标记。我想将此url结构更新为
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]
当在URL[trainer profile.php?usr=SamJohn&id=MTAy]中显示.php时,此htaccess代码工作正常,但它重定向到另一个URL,显示404错误
/OscarKemjika/MTAy/?usr=OscarKemjika&id=MTAy
Iam使用以下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
提前谢谢。试试换衣服
[a-z0-9]
到
A-Z表示区分大小写Flag[NC]表示nocase,=不区分大小写
[a-zA-Z0-9]