Htaccess url 重写帮助

发布于 2024-10-21 09:09:55 字数 1084 浏览 0 评论 0原文

我有这个 htaccess


RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.test\.com$ [NC]
RewriteRule ^(.*)$ http://www.test.com/$1 [R=301,L]



RewriteRule ^home.html$ index__.php [L]
RewriteRule ^prodotti.html$ prodotti.php [L]
RewriteRule ^azienda.html$ azienda.php [L]
RewriteRule ^news.html$ news.php [L]
RewriteRule ^outlet.html$ outlet.php [L]
RewriteRule ^contatti.html$ contatti.php [L]

RewriteRule ^news-(.*).html$ news.php?id=$1 [L]

RewriteRule ^arr.html$ prodotti-cat.php?cat=a [L]
RewriteRule ^sed.html$ prodotti-cat.php?cat=s [L]
RewriteRule ^par.html$ prodotti-cat.php?cat=p [L]
RewriteRule ^cont.html$ prodotti-cat.php?cat=c [L]
RewriteRule ^comp.html$ prodotti-cat.php?cat=co [L]

RewriteRule ^outlet/([a-zA-Z0-9_-]+).html$ outlet-dett.php?prd=$1 [L]

RewriteRule ^(.*)/(.*)/$ prodotti-cat.php?cat=$1&f=$2 [L]
RewriteRule ^(.*)/(.*).html$ prodotti-dett.php?cat=$1&prd=$2 [L]

如果我在浏览器中写入 http://www.test.it/outlet /test-2.html 我找不到... 为什么??? 帮助!!!

I have this htaccess


RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.test\.com$ [NC]
RewriteRule ^(.*)$ http://www.test.com/$1 [R=301,L]



RewriteRule ^home.html$ index__.php [L]
RewriteRule ^prodotti.html$ prodotti.php [L]
RewriteRule ^azienda.html$ azienda.php [L]
RewriteRule ^news.html$ news.php [L]
RewriteRule ^outlet.html$ outlet.php [L]
RewriteRule ^contatti.html$ contatti.php [L]

RewriteRule ^news-(.*).html$ news.php?id=$1 [L]

RewriteRule ^arr.html$ prodotti-cat.php?cat=a [L]
RewriteRule ^sed.html$ prodotti-cat.php?cat=s [L]
RewriteRule ^par.html$ prodotti-cat.php?cat=p [L]
RewriteRule ^cont.html$ prodotti-cat.php?cat=c [L]
RewriteRule ^comp.html$ prodotti-cat.php?cat=co [L]

RewriteRule ^outlet/([a-zA-Z0-9_-]+).html$ outlet-dett.php?prd=$1 [L]

RewriteRule ^(.*)/(.*)/$ prodotti-cat.php?cat=$1&f=$2 [L]
RewriteRule ^(.*)/(.*).html$ prodotti-dett.php?cat=$1&prd=$2 [L]

If i write in my browser http://www.test.it/outlet/test-2.html i get NOT FOUND...
Why???
Help!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁拥 2024-10-28 09:09:55

http://www.test.it/outlet/test-2.html 将被翻译为

http://www.test.it/outlet-dett.php?prd=test-2

检查该文件是否存在。

在字符 ? 之后并包括字符 ? 的任何内容都称为查询字符串,因此情况如下:

  • 服务器加载 outlet-dett.php
  • 并向其传递名为 prd 且值为 test-2 的变量。
  • 然后,outlet-dett.php 中的 PHP 脚本根据 prd 的值显示数据。

重写规则中的 $1 称为反向引用。它引用正则表达式中第一个括号之间的匹配。

http://www.test.it/outlet/test-2.html will be translated to

http://www.test.it/outlet-dett.php?prd=test-2

Check if that file exists.

Anything after and including the character ? are called the query string, so this is how it goes:

  • The server loads outlet-dett.php
  • and passes it the variable named prd with the value test-2.
  • then the PHP script in outlet-dett.php displays the data depending on the value of prd.

The $1 in your rewrite rule is called a back reference. It references the match between the first parenthesis in your RegEx.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文