Apache重写规则适用于主页但不适用于链接

时间:2014-06-03 23:15:57

标签: apache .htaccess mod-rewrite redirect kirby

我在/www/文件夹中有一个网站。在父目录中,我有一个.htaccess文件,该文件通过/www/目录,因此就好像它不存在一样。

在该文件夹中,我将Kirby CMS作为子模块使用它自己的网址重写规则。主页显示为http://mywebsite.local,但链接显示为http://mywebsite.local/www/page-name。它们是在PHP中动态生成的,而不是硬编码的。

从网址中手动删除/www/表示重定向工作正常。所以它必须是Kirby问题。

kirbycms是一个git子模块,我已按照本教程http://rimann.org/blog/kirby-git-setup进行操作。

结构:

|- .htaccess
|- www
|- |- index.php
|- |- .htaccess
|- |- kirbycms
|- |- |- kirby
|- |- themes
|- |- |- v9
|- |- |- |- site

root .htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond $1 !^www/
    RewriteRule ^(.*)$ www/$1 [L]
</IfModule>

kirby .htaccess:

# Kirby .htaccess

# rewrite rules
<IfModule mod_rewrite.c>

# enable awesome urls. i.e.:
# http://yourdomain.com/about-us/team
RewriteEngine on

# make sure to set the RewriteBase correctly
# if you are running the site in a subfolder.
# Otherwise links or the entire site will break.
#
# If your homepage is http://yourdomain.com/mysite
# Set the RewriteBase to:
#
# RewriteBase /mysite
#
RewriteBase /

# block text files in the content folder from being accessed directly
RewriteRule ^content/(.*)\.(txt|md|mdown)$ error [R=301,L]

# block all files in the site folder from being accessed directly
RewriteRule ^site/(.*) error [R=301,L]

# block all files in the kirby folder from being accessed directly
RewriteRule ^kirby/(.*) error [R=301,L]

# leave robots.txt alone for search engines
RewriteRule ^robots.txt robots.txt [L]

# make panel links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^panel/(.*) panel/index.php [L]

# make site links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]

</IfModule>


# Additional recommended values
# Remove comments for those you want to use.
#
# AddDefaultCharset UTF-8
#
# php_flag short_open_tag on

的index.php:

<?php

/*

---------------------------------------
Document root of your site
---------------------------------------
this should be identical with the directory
in which your index.php is located

*/

$root = dirname(__FILE__);



/*

---------------------------------------
Kirby system folder
---------------------------------------

by default this is located inside the root directory
but if you want to share one system folder for
multiple sites, you can easily change that here
and link to a shared kirby folder somewhere on your
server

*/

$rootKirby = $root . '/kirbycms/kirby';



/*

---------------------------------------
Your site folder
---------------------------------------

Your site folder contains all the site specific files
like templates and snippets. It is located in the root
directory by default, but you can move it if you want.

*/

$rootSite = $root . '/theme/v9/site';



/*

---------------------------------------
Your content folder
---------------------------------------

Your content folder is also located in the root
directory by default. You can change this here.
It can also be changed later in your site/config.php

*/

$rootContent = $root . '/content';


// Try to load Kirby
if(!file_exists($rootKirby . '/system.php')) {
  die('The Kirby system could not be loaded');
}

require_once($rootKirby . '/system.php');

有谁知道如何设置链接,以便他们没有/www/

1 个答案:

答案 0 :(得分:1)

解决方案很简单。这是一个Kirby配置选项,可以将该站点放在子文件夹中。

<{1>} site/config/config.php中有一个c::set('subfolder', false);选项需要设置为true。

然后www消失。