带有.htaccess的mod_rewrite到spoof子目录

shs*_*mer 1 .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]
Run Code Online (Sandbox Code Playgroud)

如果请求的网址是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]
Run Code Online (Sandbox Code Playgroud)

dvb*_*dvb 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