1

我无法确定正确的条目以放入我的 .htaccess 文件中。

我想做的是:

1) 允许对某些文件类型的所有请求正常工作。(即 jpg|gif|png|css|js|ico)

这将允许网页中包含的所有文件正常工作。

2)所有对“登录”的请求都被重定向到登录页面,带有参数。例如

/login
/Login        (different case)
/login/
/login/index.py
/login/scipt/index.py
/login?id=1&attr=foobar
/login/index.py?mode=1&attr=foobar?name=Billy
/login/scipt/index.py?index=999
/login/?anotherparam=value      (basically, the parameter list can vary)

应该全部重定向到:

/login.py

那些带有 GET 参数的,应该重定向到:

/login.py?(copied list of parameters without these brackets)

3) 其他所有内容都应重定向到根目录(即'/'),保留所有参数。例如

/NotAPage.html
/NotAFolder/
/NotAFolder/NotAPage.html
/NotAPage.html?v=1&k=2
/NotAFolder/?a=2
/NotAFolder/NotAPage.html?a=99&b=55&c=99   (again, the parameter list can vary)

应该全部重定向到:

/

那些带有 GET 参数的,应该重定向到:

/?(copied list of parameters without these brackets)

到目前为止,我已经做到了这一点:

#Make PY (Python) files executable outside of CGI-BIN
AddHandler cgi-script .py
Options +ExecCGI

# Turn on URL rewriting engine
RewriteEngine On

# Allow these file types to pass through untouched
RewriteCond %{REQUEST_URI} !\.(jpg|gif|png|css|js|ico)$
# Redirect all other requests to index.py
RewriteRule (.*) index.py [L,PT]

我相信,它正在让所有东西(除了后缀列表)重定向到 index.py,带有参数,但它还没有做我需要的一切。

谁能指出我正确的方向?

4

1 回答 1

1
AddHandler cgi-script .py
Options +ExecCGI

RewriteEngine On

RewriteCond %{REQUEST_URI} !\.(jpg|gif|png|css|js|ico)$ [NC]
RewriteCond %{REQUEST_URI} !^login [NC]
RewriteRule . index.py [QSA,PT]

RewriteCond %{REQUEST_URI} !\.(jpg|gif|png|css|js|ico)$ [NC]
RewriteCond %{REQUEST_URI} ^login [NC]
RewriteRule . login.py [QSA,PT]

PT标志暗示L标志:将停止重写以便将请求传递到下一个处理阶段。

请注意,该PT标志隐含在每个目录的上下文中,例如<Directory>节或.htaccess文件中。避免这种情况的唯一方法是重写为-.

于 2012-11-02T19:03:56.857 回答