2012-01-09 53 views
0

我有一個Drupal網站,其網址別名爲/news,但客戶端還需要將文件存儲在物理/news/文件夾爲傳統目​​的(從舊時事通訊等鏈接文件)。配置htaccess忽略webroot子文件夾,但提供該子文件夾中包含的文件,webroot包含URL別名webapp

site.com/news服務403 Forbidden,但物理文件夾優先於CMS,肯定是在Drupal 6標準htaccess中定義的。

是否有可能配置一個單獨的htaccess文件,它可能駐留在/news/之內,所以我不需要在未來軟件更新的情況下襬弄Drupal標準htaccess,因爲這些更改可能會被覆蓋。然而,這是不太可能的,因爲它是一個Drupal 6站點,它與這個主要版本一樣成熟,所以修改webroot htaccess也不是不合理的。

編輯:

當前的.htaccess內容

# 
# Apache/PHP/Drupal settings: 
# 

# Protect files and directories from prying eyes. 
<FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$"> 
    Order allow,deny 
</FilesMatch> 

# Don't show directory listings for URLs which map to a directory. 
Options -Indexes 

# Follow symbolic links in this directory. 
Options +FollowSymLinks 

# Make Drupal handle any 404 errors. 
ErrorDocument 404 /index.php 

# Force simple error message for requests for non-existent favicon.ico. 
<Files favicon.ico> 
    # There is no end quote below, for compatibility with Apache 1.3. 
    ErrorDocument 404 "The requested file favicon.ico was not found. 
</Files> 

# Set the default handler. 
DirectoryIndex index.php 

# Override PHP settings. More in sites/default/settings.php 
# but the following cannot be changed at runtime. 

# PHP 4, Apache 1. 
<IfModule mod_php4.c> 
    php_value magic_quotes_gpc    0 
    php_value register_globals    0 
    php_value session.auto_start    0 
    php_value mbstring.http_input    pass 
    php_value mbstring.http_output   pass 
    php_value mbstring.encoding_translation 0 
</IfModule> 

# PHP 4, Apache 2. 
<IfModule sapi_apache2.c> 
    php_value magic_quotes_gpc    0 
    php_value register_globals    0 
    php_value session.auto_start    0 
    php_value mbstring.http_input    pass 
    php_value mbstring.http_output   pass 
    php_value mbstring.encoding_translation 0 
</IfModule> 

# PHP 5, Apache 1 and 2. 
<IfModule mod_php5.c> 
    php_value magic_quotes_gpc    0 
    php_value register_globals    0 
    php_value session.auto_start    0 
    php_value mbstring.http_input    pass 
    php_value mbstring.http_output   pass 
    php_value mbstring.encoding_translation 0 
</IfModule> 

# Requires mod_expires to be enabled. 
<IfModule mod_expires.c> 
    # Enable expirations. 
    ExpiresActive On 

    # Cache all files for 2 weeks after access (A). 
    ExpiresDefault A1209600 

    <FilesMatch \.php$> 
    # Do not allow PHP scripts to be cached unless they explicitly send cache 
    # headers themselves. Otherwise all scripts would have to overwrite the 
    # headers set by mod_expires if they want another caching behavior. This may 
    # fail if an error occurs early in the bootstrap process, and it may cause 
    # problems if a non-Drupal PHP file is installed in a subdirectory. 
    ExpiresActive Off 
    </FilesMatch> 
</IfModule> 

# Various rewrite rules. 
<IfModule mod_rewrite.c> 
    RewriteEngine on 

    # If your site can be accessed both with and without the 'www.' prefix, you 
    # can use one of the following settings to redirect users to your preferred 
    # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option: 
    # 
    # To redirect all users to access the site WITH the 'www.' prefix, 
    # (http://example.com/... will be redirected to http://www.example.com/...) 
    # adapt and uncomment the following: 
    # RewriteCond %{HTTP_HOST} ^example\.com$ [NC] 
    # RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] 
    # 
    # To redirect all users to access the site WITHOUT the 'www.' prefix, 
    # (http://www.example.com/... will be redirected to http://example.com/...) 
    # uncomment and adapt the following: 
    # RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] 
    # RewriteRule ^(.*)$ http://example.com/$1 [L,R=301] 

    # Modify the RewriteBase if you are using Drupal in a subdirectory or in a 
    # VirtualDocumentRoot and the rewrite rules are not working properly. 
    # For example if your site is at http://example.com/drupal uncomment and 
    # modify the following line: 
    # RewriteBase /drupal 
    # 
    # If your site is running in a VirtualDocumentRoot at http://example.com/, 
    # uncomment the following line: 
    # RewriteBase/

    # Rewrite URLs of the form 'x' to the form 'index.php?q=x'. 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_URI} !=/favicon.ico 
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] 
</IfModule> 

# $Id: .htaccess,v 1.90.2.5 2010/02/02 07:25:22 dries Exp $ 
+0

請將您當前的htaccess內容添加到您的文章中。 – Gerben 2012-01-09 17:58:40

+0

增加了htaccess,謝謝。 – DanH 2012-01-11 02:49:06

+0

您是否可以不只是將用於新聞模塊的名稱更改爲newsitems或類似的東西? – 2013-03-29 11:48:53

回答

0

/news/文件夾我創建了一個新的.htaccess文件具有以下內容:

RewriteEngine on 
RewriteCond %{REQUEST_URI} !-f 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ ../index.php?q=news [L,QSA] 

編輯:

新增這是不是在我的分級環境需要第二的RewriteCond,但在生產環境中似乎是需要的。

1

我會假設你的.htaccess是做標準檢查Web應用程序做的是,如果URI是不是一個文件或目錄重定向到前端控制器,沿着線的東西...

RewriteCond %{REQUEST_URI} !-f 
RewriteCond %{REQUEST_URI} !-d 
RewriteRules .* index.php 

因爲你的情況/news是一個目錄,第二個RewriteCond沒有被滿足,因此它只是試圖訪問該文件夾並獲得權限錯誤。最簡單的解決方案可能是添加該文件的例外。確切的要求取決於你當前的.htaccess文件的樣子,但在頂部放置類似下面的內容可能會完成這項工作。

RewriteRule ^/news$ index.php [QSA,L] 
+0

謝謝你,不幸的是沒有工作:(。我更新了我的問題與進一步的發現 – DanH 2012-01-11 03:51:29

+0

其實我找出答案,因爲我正在更新我的問題! – DanH 2012-01-11 04:08:56

相關問題