【发布时间】:2012-03-28 09:43:37
【问题描述】:
这是我的 .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 别名,可用于缩短长 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.xml → http://example.com/file1.xml
http://example.com/cache/Sitemaps/file2.xml → http://example.com/file2.xml
http://example.com/cache/Sitemaps/file3.xml → http://example.com/file3.xml
...等等! (其中 → 代表“别名或缩写为”)
我该怎么做?我应该将它添加到我的 .htaccess 文件的什么位置(如上所示)?谢谢。
【问题讨论】:
标签: .htaccess mod-rewrite url-rewriting