【问题标题】:Htaccess multiple redirect for one page一页的Htaccess多个重定向
【发布时间】:2014-06-19 20:17:49
【问题描述】:

我有一个问题: 我为我未来的网站制作了一个空白页面,但我遇到了问题。

这些 url (account.php) 提供一个页面:

http://site.domain/en/account/ -- 可以访问,但如果没有 / ,我无法访问它
http://site.domain/en/account/create/ -- 可以访问,但我有同样的问题 http://site.domain/en/account/create/verify/ -- 无法使用当前 htaccess 访问

我的 htaccess 看起来像这样:

RewriteEngine On
AddDefaultCharset UTF-8
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{HTTP:Accept-Language} ^([a-z]{2})- [NC]
## Rewrite Rules
RewriteRule ^account/?$ /%1/%{REQUEST_URI} [L,NC,R]
RewriteRule ^([a-z]{2})/(account)/([^/]+)/([^/]+)?$ /$2.php?language=$1&type=$3 [L,NC,QSA]

所以我想做的是让所有重定向都可以通过 htaccess 访问。

例如,使用上面提到的 htaccess 中的数据,我可以访问帐户页面并创建页面,但不能验证页面。如果我将其更改为:

RewriteRule ^([a-z]{2})/(account)/([^/]+)/([^/]+)/([^/]+)?$ /$2.php?language=$1&type=$3&subtype=$4 

我可以访问创建和验证页面,但不能访问帐户页面本身。

所以我想要实现的是能够使用一个 htaccess 规则访问所有这 3 个页面,因此基本上只需使用 htaccess 重定向用户并且无需 php 帮助,即使 account.php 确定哪个请求已制作并为请求提供正确的页面

有没有关于 htaccess 和相关问题的好书可以阅读,因为我不知道它是什么以及如何使用它

【问题讨论】:

  • 我认为您可以查看 AskApache askapache.com/htaccess/htaccess.html 以获得 htaccess。至于您列出的其他问题,我不确定我是否理解它们......您能否编辑问题以更好地解释一下?谢谢:)
  • @tattvamasi 我已经更新了问题

标签: php .htaccess mod-rewrite redirect


【解决方案1】:

这样吧:

AddDefaultCharset UTF-8

RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]

RewriteCond %{HTTP:Accept-Language} ^([a-z]{2})- [NC]
## Rewrite Rules
RewriteRule ^account/?$ /%1%{REQUEST_URI} [L,NC,R]

RewriteRule ^([a-z]{2})/(account)(?:/([^/]+)(?:/([^/]+))?)?/?$ /$2.php?language=$1&type=$3 [L,NC,QSA]

【讨论】:

  • 现在我可以访问帐户并验证,但不能创建,返回 404 错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-19
  • 1970-01-01
  • 2012-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多