【问题标题】:Htaccess rewrite URL with virtual directory and 2 variablesHtaccess 用虚拟目录和 2 个变量重写 URL
【发布时间】:2015-08-30 07:10:49
【问题描述】:

这是我的网址...

result.php?team=arsenal&player=ospina

我想要这个

mysite.com/virtualdirectory/arsenal/ospina.html

我试过这段代码..无法工作..未找到

RewriteRule ^(.*)/(.*)/(.*).html$ result.php?team=$2&player=$3 [L]

在此服务器上找不到请求的 URL /subfolder/arsenal/ospina.html。

Apache/2.2.8 (Win32) PHP/5.2.6 服务器在 localhost 端口 80

感谢您的帮助, 最好的问候!!

【问题讨论】:

  • 你能提供更多细节吗?你的问题不清楚
  • 样本字符串中没有.html
  • 你的问题解决了吗?

标签: regex apache .htaccess url rewriting


【解决方案1】:

好的,我假设你想从

更改 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

希望对你有帮助

【讨论】:

    【解决方案2】:

    在您的 .htaccess 文件中

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/?([^\.*]+)/([^\.*]+)/([^\.*]+).html$ result.php?team=$2&player=$3 [L,QSA]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-02
      • 1970-01-01
      • 1970-01-01
      • 2013-11-06
      • 2015-02-06
      • 1970-01-01
      • 1970-01-01
      • 2015-09-25
      相关资源
      最近更新 更多