Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 如何为目录中的所有文件创建别名?_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

.htaccess 如何为目录中的所有文件创建别名?

.htaccess 如何为目录中的所有文件创建别名?,.htaccess,mod-rewrite,url-rewriting,.htaccess,Mod Rewrite,Url Rewriting,这就是我的.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

这就是我的.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>
#原件
#如果修改此文件,请将上面的行更改为:#已修改
重新启动发动机
#某些主机可能需要以下行。
#如果香草在子文件夹中,则需要在/之后指定它。
#(例如,您在/forum中添加了香草,因此将下一行更改为:RewriteBase/forum)
#重写基/
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^(.*)$index.php\?p=$1[QSA,L]
我刚刚读到,使用.htaccess中的重写规则,我可以创建URL别名,用于缩短长URL。我想创建一个通配符重写规则,以便此目录中的所有文件:
http://example.com/cache/Sitemaps/
被缩短(未重定向)为
http://example.com/*

例如,如果file1.xml、file2.xml、file3.xml。。。等等是驻留在
http://example.com/cache/Sitemaps/
,我想要:




等等(在哪里→ 表示“别名或缩写为”)


我该怎么做?我应该将它添加到我的.htaccess文件(如上所示)的什么位置?谢谢。

这是您修改的.htaccess,请将其放在文档\u根目录中:

# 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>
#已修改
#如果修改此文件,请将上面的行更改为:#已修改
重新启动发动机
#某些主机可能需要以下行。
#如果香草在子文件夹中,则需要在/之后指定它。
#(例如,您在/forum中添加了香草,因此将下一行更改为:RewriteBase/forum)
重写基/
#将/cache/Sitemaps/foo.xml缩短为/foo.xml
重写规则^((?!cache/Sitemaps/).\.xml)$cache/Sitemaps/$1[NC,L]
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^(.*)$index.php?p=$1[QSA,L]