开发者

How to perform redirection without a file extension in the URL on Apache

Is there a GENERIC way to point a page to 开发者_JAVA技巧another page if the page has no extension specified without physically redirecting the user to the actual 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 


Maybe this is what you need:

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

Edit:

Add this RewriteCond to check for an extension:

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


yes , you can do it by rewrite rules but you should know something about URL or some conditions about that to prevent rewritting other URLs.

for example rewrite rule for your given URL is:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜