【问题标题】:.htaccess, make all urls serve the same page secretly.htaccess,让所有 url 秘密服务于同一个页面
【发布时间】:2014-05-13 00:59:00
【问题描述】:

有没有办法让 htaccess 将所有 url 重定向到同一页面,除非它存在?在这种情况下,我希望重定向在幕后。这意味着用户的 URL 不能更改。我需要来自 url 的数据,我只是通过 PHP 服务器处理所有页面内容。写一些疯狂的 php 东西。 ;)

我当前的代码:

RewriteEngine On

#Remove www
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "http\:\/\/example\.com\/" [R=301]

#Remove Ending Slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/phpmyadmin/$
RewriteCond %{REQUEST_URI} (.*)$
RewriteRule ^(.+)/$ http://example.com/$1 [R=301]

#Get page from /page/
RewriteCond %{REQUEST_URI} !^/page$
RewriteCond %{DOCUMENT_ROOT}/page%{REQUEST_URI} -f
RewriteRule ^ http://example.com/page_it_should_go_to.php [L]

DirectoryIndex header.php 

正是我需要的:

  1. 所有页面,除非确切的 url 是服务器上的真实位置或在位置 /page 中,否则需要提供 example.com/page_it_should_go_to.php
  2. phpMyAdmin 需要继续工作
  3. 没有www
  4. home 后面没有斜杠

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:

    啊哈!我发现出了什么问题。

    原来它是多方面的!这是我从谷歌搜索中得到的:

    1. 您不能使用绝对网址,因为这会重定向用户。
    2. 当我重定向到 /page 时,我从后面留下了 RewriteCond %{DOCUMENT_ROOT}/page%{REQUEST_URI} -f,它正在检查它是否存在于页面目录中。哎呀。

    感谢 StackOverflow!今天我将自己征服它。 =D

    【讨论】:

      猜你喜欢
      • 2013-02-17
      • 2013-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-14
      • 2018-08-14
      • 2021-06-05
      相关资源
      最近更新 更多