.htaccess htaccess动态文件夹重写

.htaccess htaccess动态文件夹重写,.htaccess,.htaccess,这就是我的情况,我已经想了好几天怎么做了,这对我来说太复杂了。我想重写以下内容: http://demo.myurl.com/proevent/event1 to http://demo.myurl.com/index.php?url=proevent&path=event1 http://demo.myurl.com/proevent/admin to http://demo.myurl.com/admin - when folders exist under that locat

这就是我的情况,我已经想了好几天怎么做了,这对我来说太复杂了。我想重写以下内容:

http://demo.myurl.com/proevent/event1 to http://demo.myurl.com/index.php?url=proevent&path=event1 

http://demo.myurl.com/proevent/admin to http://demo.myurl.com/admin - when folders exist under that location I want to have them loaded and not falling to /index.php
现在说“proevent”和“event1”是完全动态的

我肯定知道的文件夹是:admin,inc,现有的照片,其余的是动态的

在所有重定向的情况下,我都希望从路径中知道已打开的内容,并给出错误消息

以下是我到目前为止的情况:

跳过斜杠,因为人们忘记放置斜杠,并且文件夹不存在

    RewriteCond %{REQUEST_URI} !(\.|/$)
    RewriteRule (.*) /$1/ [R=301,L]
if dir/file exists (doesn't really work)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ([^/]*)/(.*) /$2%{REQUEST_URI} [R]
也不知道它什么时候起作用,因为在以前的案例中它可能会掉下来

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/(/?.*?)([^/]*)$ index.php?url=$1&path=$2 [L]
感谢您的帮助

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} /([^/]*)$
RewriteCond %{DOCUMENT_ROOT}/%1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/%1 -d
RewriteRule /(.*)$ /%1/ [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/(/?.*?)$ index.php?url=$1&path=$2 [L]
我会帮你的

第一部分检查完整目录或子目录是否为文件,第二部分在第一部分失败时重定向

更清楚地说

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
首先检查这是否是真实的文件或目录

RewriteCond %{REQUEST_URI} /([^/]*)$
根据您的请求获取URL的最后一部分

RewriteCond %{DOCUMENT_ROOT}/%1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/%1 -d
这些检查是/(URL的最后一部分)文件或目录。这使用了“重写”的反向引用功能。%1在一秒钟内引用最后一个正则表达式的第一个块

RewriteRule /(.*)$ /%1/ [L]
如果是目录,我们重写

否则,下一部分是显而易见的,只需重写您设置的get条件。

可能重复的