Как создать псевдонимы для всех файлов в каталоге? - PullRequest
0 голосов
/ 28 марта 2012

Вот как выглядит мой файл .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.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 Ответ

1 голос
/ 28 марта 2012

Вот ваш модифицированный .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>
...