使用.htaccess添加文件结尾?

时间:2010-12-16 12:01:57

标签: apache .htaccess

我正在尝试使用.htaccess将文件结尾(.kml)添加到网址但是它无法正常工作

网址为http://resihop.nu/kml 我希望它是http://resihop.nu/kml.kml这就是我的尝试:

RewriteRule ^ kml.kml $ kml

这是我的全部.htacess:

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

RewriteRule ^kml\.kml$ kml

2 个答案:

答案 0 :(得分:0)

这适用于您使用自己的扩展程序的情况:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.+)\.kml$ /$1.php [NC,L]

然后您可以访问任何扩展名为.kml的文件,例如hello.kml。

希望这有帮助。

答案 1 :(得分:0)

您需要告诉服务器如何处理.kml文件。将此行添加到.htaccess

AddType application/x-httpd-php .kml

(假设您希望将.kml文件解析为PHP。)

编辑:没关系,我只是重新阅读你的问题,我意识到这不是你的问题。别管我了!