【问题标题】:URL Rewrite PHP and .htaccess [duplicate]URL重写PHP和.htaccess [重复]
【发布时间】:2013-06-23 05:14:32
【问题描述】:

我需要从这里更改网站 URL:

www.thesite.com/thepage.php?lang=it

到这里:

www.thesite.com/it/thepage.php

但即使文件夹 it 不存在,我也需要它来工作。

当然,我还需要 PHP 文件将 www.thesite.com/it/thepage.php 读回这个 www.thesite.com/thepage.php?lang=it

我查看了很多关于 StackOverflow 的帖子和文档,但无法弄清楚。

【问题讨论】:

  • 你试过阅读the documentation吗?
  • 我确实尝试过但无法弄清楚,否则我不会问...对于昆汀,我确实看过其他答案但仍然无法弄清楚...我可能很愚蠢,但是...:D
  • 同时显示你的 .htaccess 的代码
  • 您的网络服务器是 Apache 吗?还是别的什么?
  • 我认为是 Apache,因为你给我的第一行工作“RewriteRule ^([^//]+)$ thepage.php?lang=$1 [QSA,L]”。否则我在哪里可以找到我拥有的服务器?

标签: php .htaccess url rewrite uri


【解决方案1】:

这个怎么样

RewriteEngine on
RewriteRule ^([^//]+)$ thepage.php?lang=$1 [QSA,L]

要让thepage.php 也成为动态的,试试这个

www.thesite.com/it/thepage.php

RewriteEngine on
RewriteRule ^([^//]+)/([^//]+)$ $2?lang=$1 [QSA,L]

【讨论】:

  • 听起来不错,但“页面”可以是任何页面,例如 index.php、this.php、other.php... 等等。会是什么?
  • 不明白为什么但它不起作用:http://www.aquapol.mc/index.php?lang=it
  • 它工作完美我已经在我的本地主机上尝试过你的网址应该是http://www.aquapol.mc/it/index.php
  • 好的,您是否尝试点击上面的链接?它适用于您的浏览器吗?我的不起作用,我看到那个地址并且没有进入 /it/index.php 我的 .htaccess 只有这两行: RewriteEngine on RewriteRule ^([^//]+)/([^//] +)$ $2?lang=$1 [QSA,L]
  • 那肯定和你的服务器配置有关
【解决方案2】:
RewriteEngine on
RewriteRule ^([a-zA-z]+)/(.+) $2?lang=$1

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2023-03-05
  • 1970-01-01
  • 2010-11-04
  • 2018-12-03
  • 1970-01-01
  • 2016-12-05
  • 2012-04-29
相关资源
最近更新 更多