带有.htaccess的mod_rewrite到spoof子目录

时间:2010-12-28 22:41:22

标签: .htaccess mod-rewrite

我在子域名subdomain.domain.com/appname上运行了django应用,但我不希望应用名称显示在我的任何网址中。我通过.htaccess

完成了这项工作
RewriteEngine On

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

如果请求的网址是subdomain.domain.com/home并且从subdomain.domain.com/appname/home提供,则会出现这种情况。

但是,我还想完成相反的操作,其中请求的网址为subdomain.domain.com/appname/home,显示的网址更改为subdomain.domain.com/home,然后触发上述规则并从subdomain.domain.com/appname/home

提供

我尝试了以下操作,但遇到错误,我有一个循环

RewriteEngine On

RewriteCond %{REQUEST_URI} appname
RewriteRule ^appname/(.*)$ /$1 [N,R=301]

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

1 个答案:

答案 0 :(得分:5)

尝试没有'N'标志:

'next|N' (next round)
Re-run the rewriting process (starting again with the first rewriting rule). This time, the URL to match is no longer the original URL, but rather the URL returned by the last rewriting rule. This corresponds to the Perl next command or the continue command in C. Use this flag to restart the rewriting process - to immediately go to the top of the loop.
Be careful not to create an infinite loop!

http://httpd.apache.org/docs/current/mod/mod_rewrite.html