【问题标题】:.htaccess MOD_rewrite for the entire site.htaccess MOD_rewrite 整个站点
【发布时间】:2011-10-20 20:49:04
【问题描述】:

我有一个位于 www.domain/store 下的网站

我想为整个网站使用 MOD_rewrite 来摆脱 store。

这可能与mod_rewrite有关吗??

该网站基于 Opencart 构建。

我已尝试以下建议: 我收到内部服务器错误,所以我查看了 Apache 错误日志,以下是错误:

[Sun Oct 23 03:02:09 2011] [error] [client 120.144.194.243] File does not exist: /home/favstayc/public_html/404.shtml
[Sun Oct 23 03:02:09 2011] [error] [client 120.144.194.243] File does not exist: /home/favstayc/public_html/favicon.ico
[Sun Oct 23 03:02:09 2011] [error] [client 120.144.194.243] client denied by server configuration: /home/favstayc/public_html/error_log
[Sun Oct 23 03:02:09 2011] [error] [client 120.144.194.243] client denied by server configuration: /home/favstayc/public_html/.htaccess

好的,我现在得到了答案。下面就是答案!

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)store
RewriteRule ^(.*)$ store/$1 [L]

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    很简单,使用这种模式,所有东西都会重定向到/store/whatever,对用户来说是不可见的。所以你的用户输入http://example.com/some-product,Apache为用户http://example.com/store/some-product服务。

    RewriteEngine On
    #RewriteCond %{REQUEST_URI} !^store.*$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /store$1 [L,QSA]
    

    【讨论】:

    • 我不想让商店出现在网址上。有可能吗?
    • 这正是这条规则的作用。除非您添加 [R],否则标记它不会重定向用户的浏览器。
    • @hybmg58 检查您的 Apache error_log 以查看错误是什么。另请参阅上面添加的RewriteCond
    • 好的,我现在收到这个错误:这个网页有一个重定向循环
    • @hybmg58 查看附加项,它检查请求的项目是否为真实文件(即,它存在于store 目录中)。如果是这样,则不会进行重写,因此您不会出现循环。
    猜你喜欢
    • 2015-08-22
    • 2013-03-05
    • 1970-01-01
    • 2011-01-14
    • 2018-07-23
    • 1970-01-01
    • 2011-01-12
    • 2014-05-18
    • 1970-01-01
    相关资源
    最近更新 更多