2011-10-05 70 views
0

如果页面没有指定扩展名而没有将用户实际重定向到实际的URL,是否有一种通用的方式将页面指向另一页?如何在Apache中的URL上没有文件扩展名的情况下执行重定向

e.g. 
http://www.mydomain.com/ points to http://www.mydomain.com/public 
http://www.mydomain.com/auth points to http://www.mydomain.com/public/auth 
http://www.mydomain.com/auth/process points to http://www.mydomain.com/public/auth/process 
http://www.mydomain.com/auth/process/done points to http://www.mydomain.com/public/auth/process/done 

回答

2

也许这就是你需要:

RewriteCond %{REQUEST_URI} !^/(public)(.*)$ [NC] 
RewriteRule ^(.*)$ /public/$1 [L] 

编辑:

添加此的RewriteCond检查的扩展名:

RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ 
+0

对不起,没有阅读,起初只有在没有扩展的情况下才想'重定向'。 – Fabian

+0

嗨,感谢您的回复。我会尝试一下,并在几个方面回复你。顺便说一句,你会如此善良的发布规则的确切顺序?对不起,对于htaccess来说真的很陌生。 –

+0

不客气!请使用以下命令: RewriteCond%{REQUEST_URI}!(\。[a-zA-Z0-9] {1,5} |/rewriteCond%{REQUEST_URI}!^ /(public)(。*)$ [NC] )$ RewriteRule ^(。*)$/public/$ 1 [L] 尝试你的规则,你可以用[R]代替[L],这样你就可以看到发生了什么! – Fabian

0

是的,你可以通过重写规则做,但你应该知道一些关于URL或有关防止rewritting其他URL一定的条件。

为您指定的URL例子重写规则是:

RewriteRule ^auth/(.*)$ public/auth/$1 [L] 
RewriteRule ^$ public [L] 
+0

只适用于验证页面。我正在寻找更通用的东西 –

+0

@Jourour Estrella我根据你的编辑编辑了答案。但如果你想要更多,你应该指定它们。 – undone

相关问题