【问题标题】:Rewrite everything to index.php but be able to know what page it came from.将所有内容重写为 index.php,但能够知道它来自哪个页面。
【发布时间】:2013-09-15 21:02:11
【问题描述】:

我需要一个 .htaccess 文件,将所有内容重写到我网站的 index.php 中,即www.examplesite.com

示例:我打开www.examplesite.com/designs/designs.php?tab=2013,我希望网站在后台加载http://examplesite.com/index.php,同时保持相同的URL。子文件夹designs 和文件designs.php 将不存在于服务器上,并将根据输入的URL 从index.php 内的其他服务器加载。

我的 .htaccess 已经包含一些东西,我真的不知道这意味着什么,但我认为我需要保持 RewriteCond 的开头,我不确定:

RewriteEngine on

# -FrontPage-

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName www.examplesite.com
AuthUserFile /home/designerr/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/designerr/public_html/_vti_pvt/service.grp

RewriteCond %{HTTP_HOST} ^an_other_domain_i_own\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.an_other_domain_i_own\.com$
RewriteRule ^/?$ "http\:\/\/examplesite\.com" [R=301,L]

我注意到有一个 301 重定向,我可能需要构建一个站点地图以再次编制索引。

那么,我应该在新的 .htaccess 中添加什么?我还需要在我的 PHP 代码中知道客户端看到的实际 URL 是什么,我认为是 $_SERVER['REQUEST_URI']$_SERVER['REDIRECT_URL'],我不确定。

*顺便说一下,我的网站的真实名称不是examplesite.coman_other_domain_i_own.com,但我在这篇文章中更改了它以确保我的.htaccess 的发布不会为您提供任何入侵我的网站的方法或任何类似的东西。

【问题讨论】:

    标签: php apache .htaccess redirect mod-rewrite


    【解决方案1】:

    您可以尝试这些重写规则(前提是您的第一行仍然:重写引擎开启)

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
    

    如果在服务器上找不到目录和文件,这些语句会直接调用 index.php。

    REQUEST_URI 将提供 url

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-31
      • 2012-07-22
      • 1970-01-01
      • 2011-12-30
      • 1970-01-01
      相关资源
      最近更新 更多