2012-03-28 70 views
0

這是我的.htaccess文件是什麼樣子:如何爲目錄中的所有文件創建別名?

# Original 
# If you modify this file then change the above line to: # Modified 
<IfModule mod_rewrite.c> 
    RewriteEngine On 
    # Certain hosts may require the following line. 
    # If vanilla is in a subfolder then you need to specify it after the /. 
    # (ex. You put Vanilla in /forum so change the next line to: RewriteBase /forum) 
    # RewriteBase/
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^(.*)$ index.php\?p=$1 [QSA,L] 
</IfModule> 

我剛剛閱讀了在.htaccess重寫規則,我可以創建網址別名,它可以用來縮短長的URL。我想創建一個通配符重寫規則,以便此目錄中的所有文件:http://example.com/cache/Sitemaps/都縮短(不重定向)到http://example.com/*

例如,如果file1.xml,file2.xml,file3.xml ...等等都居住在http://example.com/cache/Sitemaps/文件,我想:

http://example.com/cache/Sitemaps/file1.xmlhttp://example.com/file1.xml
http://example.com/cache/Sitemaps/file2.xmlhttp://example.com/file2.xml
http://example.com/cache/Sitemaps/file3.xmlhttp://example.com/file3.xml
...等等! (其中→表示'別名或縮寫爲')

我該如何做?我應該在哪裏添加它在我的.htaccess文件(如上所示)?謝謝。

回答

1

這是你修改的.htaccess,把它放在DOCUMENT_ROOT本身:

# Modified 
# If you modify this file then change the above line to: # Modified 
<IfModule mod_rewrite.c> 
    RewriteEngine On 
    # Certain hosts may require the following line. 
    # If vanilla is in a subfolder then you need to specify it after the /. 
    # (ex. You put Vanilla in /forum so change the next line to: RewriteBase /forum) 
    RewriteBase/

    # shorten /cache/Sitemaps/foo.xml to /foo.xml 
    RewriteRule ^((?!cache/Sitemaps/).*\.xml)$ cache/Sitemaps/$1 [NC,L] 

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

</IfModule> 
相關問題