简体   繁体   English

.htaccess文件夹重写帮助

[英]Assistance with .htaccess folder rewrite

I want to do an .htaccess rewrite for an image uploader I have on my site, but for all the tutorials I've tried, I can't get it working. 我想为网站上的图片上传器进行.htaccess重写,但是对于我尝试过的所有教程,我都无法正常运行。

Currently, the code I have uploads images to the folder: http://www.example.com/server/php/files/jkgh4f54.jpg 目前,我已将代码上传到以下文件夹: http://www.example.com/server/php/files/jkgh4f54.jpg : http://www.example.com/server/php/files/jkgh4f54.jpg

I'd like to rewrite it so when you go to this URL: http://www.example.com/jkgh4f54.jpg it is showing the image from the above location. 我想重写它,所以当您转到以下URL: http://www.example.com/jkgh4f54.jpg : http://www.example.com/jkgh4f54.jpg它显示的是上述位置的图像。

Any thoughts? 有什么想法吗? As I mentioned, there are a lot of tutorials everywhere about stuff similar to this, but I haven't been able to adapt them to work thus far for me. 正如我所提到的,到处都有很多关于类似内容的教程,但是到目前为止,我还无法适应它们。

Current .htaccess: 当前的.htaccess:

RewriteEngine On
RewriteCond %(REQUEST_FILENAME} !-f [OR]
RewriteCond %(REQUEST_FILENAME} !-d
RewriteRule ^[a-zA-Z0-9]+\.(jpe?g|png|gif|bmp)$ /server/php/files/$0 [L]
RewriteRule ^([a-zA-Z0-9]+)$ index.php?code=$1 //For URL Shortener
ErrorDocument 404 http://localhost/site.com/404.php

Using this code, when the user visits http://example.com/h3h2js.jpg , they will see the image from http://example.com/server/php/files/h3h2js.jpg , but the URL in the browser will stay the same: 使用此代码,当用户访问http://example.com/h3h2js.jpg ,他们将看到来自http://example.com/server/php/files/h3h2js.jpg的图像,但浏览器中的URL将保持不变:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[a-zA-Z0-9]+\.(jpe?g|png|gif|bmp)$ /server/php/files/$0 [L]

I have tested this code thoroughly on a clean installation of XAMPP on Windows. 我已经在Windows上的XAMPP全新安装上彻底测试了此代码。 Image names must only contain alphanumeric characters of either case (az, AZ, 0-9), and must end with a jpg, jpeg, png, gif or bmp file extension. 图像名称必须只包含任一情况下(AZ,AZ,0-9)的字母数字字符,并且必须以JPG,JPEG,PNG,GIF或BMP文件扩展名结尾。 If the requested image file already exists in the site root, the rewrite will not take place 如果所请求的图像文件已经在站点根目录中存在,则不会进行重写

Try: 尝试:

RewriteEngine on
RewriteRule ^(.*)\.jpg$ http://site.com/server/php/files/$1\.jpg [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM