Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Apache上的URL中没有文件扩展名的情况下执行重定向_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

如何在Apache上的URL中没有文件扩展名的情况下执行重定向

如何在Apache上的URL中没有文件扩展名的情况下执行重定向,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,如果一个页面没有指定扩展名,那么是否有一种通用方法可以将该页面指向另一个页面,而无需将用户重定向到实际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 t

如果一个页面没有指定扩展名,那么是否有一种通用方法可以将该页面指向另一个页面,而无需将用户重定向到实际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 

是的,你们可以通过重写规则来做到这一点,但你们应该知道一些关于URL的信息或者一些关于这些信息的条件,以防止重写其他URL

例如,给定URL的重写规则为:

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

也许这就是你需要的:

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

添加此重写条件以检查扩展:

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

这仅适用于身份验证页。我在找更多的东西generic@JhourladEstrella我根据你的编辑编辑了答案。但是如果你想要更多,你应该指定它们。对不起,我没有读到,你只想在没有分机的情况下“重定向”。嗨,谢谢你的回复。我会试试看,几分钟后再给你回复。顺便说一句,你能把规则的确切顺序公布出来吗?抱歉,htaccess是个新手,不客气!使用以下顺序:RewriteCond%{REQUEST_URI}^/(公共)(.*$[NC]重写条件%{REQUEST_URI}!(\[a-zA-Z0-9]{1,5}|/)$RewriteRule^(.*)$/public/$1[L]要尝试您的规则,您可以使用[R]而不是[L],这样您就可以看到发生了什么!