我需要创建以下规则在我的.htaccess放置
I need to create the following rule to place in my .htaccess
首先,我想execetue文件中的主文件夹(/)(如果requestedfile存在) 其次,我想搜索子文件夹中的文件 - > /子文件夹 ,如果文件不点1存在,2 ID喜欢重定向请求做的index.php什么是做到这一点的最好办法。
What would be the best way to do it.
感谢您的帮助:)
PS的第一点是可以消除的一个简单的解决方案。因此,如果用户输入的URL /file.jpeg服务器将检索算法用于/子文件夹这个文件,如果没有找到这个文件,会比重定向rquest做的index.php
ps The first point could be eliminated as a simpler solution. So if the user entered url /file.jpeg the server would serach for this file in /subfolder and if didn't find this file than it would redirect the rquest do index.php
推荐答案
我假设你的URL看起来像这样: somesite.com/subfolder/file.extension
。如果URL是不同的详细说明。
添加到您的的.htaccess
在的DocumentRoot
。
I am assuming your URL looks like this: somesite.com/subfolder/file.extension
. If URL is different give details.
Add this to your .htaccess
in your DocumentRoot
.
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} ^/([w]+)/([w]+.[w]+)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%2 -f
RewriteRule ^ /%2 [NC,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^ /index.php [L]
改变,以适应OP的要求。
Changed to suit OPs requirement.
RewriteEngine on
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} ([w]+.[w]+)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%1 -f
RewriteRule ^ /%1 [NC,L]
RewriteCond %{REQUEST_URI} ([w]+.[w]+)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/subdir/%1 -f
RewriteRule ^ /subdir/%1 [L]
RewriteRule ^ /index.php [L]
相关推荐
最新文章