基本上我有一个CDN设置。如何将所有子文件夹和目录重定向到不包含文件的主根目录?
/public_html/
index.html
/files/
image/
video/
video2/video2
我想所有子文件夹和目录重定向到主文件夹 - 除了文件的扩展名,因此,如果有人加载一个文件,我想,要负载上,让人们斜面视图目录。 (我不想看到一个404或禁止的消息,只是想要目录去主页)
这将节省我从上传index.php重定向。这可以通过.htaccess完成吗?
基本上我有一个CDN设置。如何将所有子文件夹和目录重定向到不包含文件的主根目录?
/public_html/
index.html
/files/
image/
video/
video2/video2
我想所有子文件夹和目录重定向到主文件夹 - 除了文件的扩展名,因此,如果有人加载一个文件,我想,要负载上,让人们斜面视图目录。 (我不想看到一个404或禁止的消息,只是想要目录去主页)
这将节省我从上传index.php重定向。这可以通过.htaccess完成吗?
# don't show any files in the folder
IndexIgnore *
ErrorDocument 403/
ErrorDocument 404/
RewriteEngine On
# disabled user to access directly to the files folder.
RewriteRule ^files(\/?)$ - [F]
# images
RewriteRule ^image/(.*)\.(jpg|png|jpeg|gif)$ /files/$1.$2 [L]
# video
RewriteRule ^video/(.*)\.(flv|avi|mov)$ /files/$1.$2 [L]
#etc...
如果您有子文件夹,则(.*)
会自动使用它。例如:
http://www.domain.com/image/i.png => /files/i.png
http://www.domain.com/image/sub1/sub2/i.png => /files/sub1/sub2/i.png
这里是一些链接,这将有助于你:
http://www.javascriptkit.com/howto/htaccess.shtml
http://www.htaccess-guide.com/
http://net.tutsplus.com/tutorials/other/the-ultimate-guide-to-htaccess-files/
http://www.bloghash.com/2006/11/beginners-guide-to-htaccess-file-with-examples/
如果我把它放在我的网址:http://www.domain.com/image/sub1/或这个http:// www .domain.com/image/sub1/sub2/ – TheBlackBenzKid
来自/ image/sub1 /文件夹的标准404。我建议有一个自定义的404和403消息。 404为这个和403当有人直接访问/文件/(查看我更新的答案) –
我们不能将所有的404和403重定向到根? – TheBlackBenzKid
是什么呢你的.htaccess样子? –
我没有做任何事情......只是得到了一个WWW删除 – TheBlackBenzKid
所以你想:/video.mpeg(文件访问的人在URL中) - > /media/video.mpeg(实际的文件)? –