【问题标题】:.htaccess rewrite rules works in sub-folder but not in the main.htaccess 重写规则在子文件夹中有效,但在主文件夹中无效
【发布时间】:2011-06-21 01:40:32
【问题描述】:

我得到了一些在主文件夹中工作的重写器 例如:主文件夹是 / 我把 htaccess 放在里面 /

这是.htaccess

Options +FollowSymlinks
RewriteBase /
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^about/(.*)/$ $1.php [L]
RewriteRule ^(.*)/download/(.*)/(.*)/(.*)/$ download-donate.php?product=$1&version=$2&os=$3&method=$4 [L]
RewriteRule ^(.*)/download/(.*)/$ download.php?product=$1&version=$2 [L]
RewriteRule ^subscribe/(.*)/$ subscribe-$1.php [L]
RewriteRule ^subscribe/(.*)/(.*)/$ subscribe-$1.php?email=$2 [L]
RewriteRule ^(.*)/screenshots/$ screenshots.php?product=$1 [L]
RewriteRule ^(.*)/(.*)/$ products.php?product=$1&page=$2 [L]
RewriteRule ^schedule-manager/$ products.php?product=schedule-manager&page=view [L]
RewriteRule ^visual-command-line/$ products.php?product=visual-command-line&page=view [L]
RewriteRule ^windows-hider/$ products.php?product=windows-hider&page=view [L]
RewriteRule ^(.*)/$ $1.php [L]

它在主文件夹中不起作用。 如果我将相同的 htaccess(将 RewriteBase 更改为 /test/)并将其放在名为“test”> /test/ 的文件夹中,它可以完美地工作 - 主文件夹和测试文件夹都有完全相同的文件!

谢谢

【问题讨论】:

  • 你可以破解它,让所有指向 .com/something 的东西都被重写为 .com/test/something .. 这不是一个正确的答案,但如果你缺乏其他选项,它可以为你工作。
  • 问题是 - 子文件夹 DID WORK

标签: .htaccess mod-rewrite


【解决方案1】:

尝试改变这两个参数的顺序:

RewriteEngine On
RewriteBase /

不确定它会做什么,但这样更有意义。

编辑

这假设您的代码位于 /test/ 文件夹中。

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^about/(.*)/$ test/$1.php [L]
RewriteRule ^(.*)/download/(.*)/(.*)/(.*)/$ test/download-donate.php?product=$1&version=$2&os=$3&method=$4 [L]
RewriteRule ^(.*)/download/(.*)/$ test/download.php?product=$1&version=$2 [L]
RewriteRule ^subscribe/(.*)/$ test/subscribe-$1.php [L]
RewriteRule ^subscribe/(.*)/(.*)/$ test/subscribe-$1.php?email=$2 [L]
RewriteRule ^(.*)/screenshots/$ test/screenshots.php?product=$1 [L]
RewriteRule ^(.*)/(.*)/$ test/products.php?product=$1&page=$2 [L]
RewriteRule ^schedule-manager/$ test/products.php?product=schedule-manager&page=view [L]
RewriteRule ^visual-command-line/$ test/products.php?product=visual-command-line&page=view [L]
RewriteRule ^windows-hider/$ test/products.php?product=windows-hider&page=view [L]
RewriteRule ^(.*)/$ test/$1.php [L]

【讨论】:

  • 以前试过。没用。并且我的订单在子文件夹中有效,因此没有理由更改订单
  • dinbrca 给了我答案!无论如何,我在 /test/ 中有相同的代码,但从 RewriteBase / 更改为 > RewriteBase /test/
【解决方案2】:

如果您的托管公司是 GoDaddy,请添加

Options -MultiViews

上方

Options +FollowSymlinks

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-22
    • 1970-01-01
    • 1970-01-01
    • 2012-08-20
    • 2012-02-24
    • 1970-01-01
    • 2014-04-03
    • 2015-03-21
    相关资源
    最近更新 更多