【问题标题】:mod_rewrite works in subdirectory not in base directorymod_rewrite 在子目录中工作而不是在基本目录中
【发布时间】:2014-12-09 18:26:09
【问题描述】:

重写规则是:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_\-.]+)/?$ storefront.php?id_user=$1 [L]

当放置在子目录中时,即:http://example.com/subdirectory/,它可以将 URL 从http://example.com/subdirectory/user 重定向到http://example.com/subdirectory/storefront.php?id_user=user

当放置在基本目录即:http://example.com/ 时,它无法将 url http://example.com/user 重定向到 http://example.com/storefront.php?id_user=user

我做错了什么?

【问题讨论】:

  • 我尝试访问网址http://example.com/user,它会将我重定向到http://example.com/
  • 此外,我尝试了简单的重写规则,例如将 fileone.html 重写为 storefront.php,当我在基本目录中键入 http://example.com/fileone.html 时它可以工作
  • fileone.html 是我尝试验证 rewriteengine 是否从基本目录工作的示例,抱歉造成混淆。只关心原始问题中描述的重写规则。
  • 问题中的代码是根目录下的整个.htaccess文件
  • 是的,但该规则不会将http://example.com/user 重定向到http://example.com/

标签: php html apache .htaccess mod-rewrite


【解决方案1】:

好的,我通过使用这个重写规则得到了我想要的效果,如果感觉是一种技巧,而不是它真正应该的方式。然后再一次..除非有人启发我了解正在发生的事情,否则它会继续工作。

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_\-.]+)/?$ http://example.com/subdirectory/storefront.php?=id_user=$1 [L]

基本上我将它重写到正在工作的目录中。但最终这不是我想要的,因为我想将子目录迁移为基目录,而这个问题正在阻止。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多