Htaccess 用虚拟目录和 2 个变量重写 URL
Htaccess rewrite URL with virtual directory and 2 variables
这是我的 URL...
result.php?team=arsenal&player=ospina
我要点赞
mysite.com/virtualdirectory/arsenal/ospina.html
我试过这段代码..无法工作..未找到
RewriteRule ^(.*)/(.*)/(.*).html$ result.php?team=&player= [L]
在此服务器上找不到请求的 URL /subfolder/arsenal/ospina。html。
Apache/2.2.8 (Win32) PHP/5.2.6 服务器在本地主机端口 80
感谢您的帮助,
最好的问候!!
在您的 .htaccess 文件中
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^\.*]+)/([^\.*]+)/([^\.*]+).html$ result.php?team=&player= [L,QSA]
好的,我假设你想改变 URI 来自
http://www.example.com/result.php?team=arsenal&player=ospina
到
http://www.example/subdirectory/arsenal/ospina.html
这就是 .htaccess 可以为您完成的
RewriteEngine on
RewriteCond %{QUERY_STRING} ^team=(.*)\&player=(.*)$
RewriteRule ^(.*)$ http://www.example.com/subdirectory/%1/%2.html [R=301]
您可以在此处使用 htaccess 测试器对其进行测试
http://htaccess.madewithlove.be/
以及一些有用的文档和学习链接:
http://httpd.apache.org/docs/2.2/rewrite/intro.html
http://code.tutsplus.com/tutorials/an-in-depth-guide-to-mod_rewrite-for-apache--net-6708
Great Video Tutorials - Understanding Apache and htaccess
希望对您有所帮助
这是我的 URL...
result.php?team=arsenal&player=ospina
我要点赞
mysite.com/virtualdirectory/arsenal/ospina.html
我试过这段代码..无法工作..未找到
RewriteRule ^(.*)/(.*)/(.*).html$ result.php?team=&player= [L]
在此服务器上找不到请求的 URL /subfolder/arsenal/ospina。html。
Apache/2.2.8 (Win32) PHP/5.2.6 服务器在本地主机端口 80
感谢您的帮助, 最好的问候!!
在您的 .htaccess 文件中
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^\.*]+)/([^\.*]+)/([^\.*]+).html$ result.php?team=&player= [L,QSA]
好的,我假设你想改变 URI 来自
http://www.example.com/result.php?team=arsenal&player=ospina
到
http://www.example/subdirectory/arsenal/ospina.html
这就是 .htaccess 可以为您完成的
RewriteEngine on
RewriteCond %{QUERY_STRING} ^team=(.*)\&player=(.*)$
RewriteRule ^(.*)$ http://www.example.com/subdirectory/%1/%2.html [R=301]
您可以在此处使用 htaccess 测试器对其进行测试 http://htaccess.madewithlove.be/
以及一些有用的文档和学习链接:
http://httpd.apache.org/docs/2.2/rewrite/intro.html
http://code.tutsplus.com/tutorials/an-in-depth-guide-to-mod_rewrite-for-apache--net-6708
Great Video Tutorials - Understanding Apache and htaccess
希望对您有所帮助