Php .htu/UA/文件夹的访问权限请求
这类似于一个问题 但答案并不适用于我 我有一个通过index.php处理程序重定向的主站点,但我想要一个在子目录Php .htu/UA/文件夹的访问权限请求,php,apache,.htaccess,mod-rewrite,redirect,Php,Apache,.htaccess,Mod Rewrite,Redirect,这类似于一个问题 但答案并不适用于我 我有一个通过index.php处理程序重定向的主站点,但我想要一个在子目录/UA/ 我需要UA/的请求通过并在子目录中处理,我已经尝试了RewriteRule^/UA-[L]和RewriteCond%{REQUEST\u URI}^/UA在my.htaccess主目录中,但此操作不起作用。我试过使用/不使用/“s 以下是我的两个.htaccess文件: RewriteEngine on ReWriteBase / # Redirect to HTTPS s
/UA/
我需要UA/
的请求通过并在子目录中处理,我已经尝试了RewriteRule^/UA-[L]
和RewriteCond%{REQUEST\u URI}^/UA
在my.htaccess主目录中,但此操作不起作用。我试过使用/不使用/“s
以下是我的两个.htaccess文件:
RewriteEngine on
ReWriteBase /
# Redirect to HTTPS site
RewriteCond %{HTTP_HOST} ^my\-site\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.my\-site\.com$
RewriteRule ^/?$ "https\:\/\/www\.mysite\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^mysite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$
RewriteRule ^/?$ "https\:\/\/www\.mysite\.com\/" [R=301,L]
#Allow UA access
RewriteRule ^/UA - [L]
#Allow certain file types to access directly
RewriteRule \.(css|js|png|jpg|gif|woff|eot|ttf|svg|ico)$ - [L]
# Catch all
RewriteCond %{REQUEST_URI} !^/UA
RewriteRule .* index.php [L]
问题是该站点继续指向Live index.php版本,而不是/UA/中URI为的版本。添加此行以始终在根目录中打开目录斜杠。htaccess:
DirectorySlash On
保持/UA/.htaccess
如下:
RewriteEngine on
ReWriteBase /UA/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|gif|woff|eot|ttf|svg|ico)$ [NC]
RewriteRule ^ index.php [L]
您如何处理像
http://domain.com/UA/当您发送https://www.mysite/UA/
Apache仅在服务器配置中启用了.htaccess
时才使用/MY/.htaccess
。我不确定是否理解您的评论,但我知道返回的页面是由/index.php生成的,而不是UA/index.php,这正是我在www.mysite.com/UA/*请求时想要的……到目前为止,我已经在网站上成功地使用了.htaccess重定向,只是子目录的行为不如预期——它是一个共享主机,因此,已配置.htaccess。通过将相同的垃圾(随机)文本放在/UA/.htaccess
顶部,验证是否启用了/UA/.htaccess
,并查看它是否生成500(内部服务器)https://www.mysite/UA/foo
request?对于探索此问题的其他人:查看对主要问题的评论,以获得帮助我的答案。如果路径请求包含子目录中的目标,即www.mysite.com/UA/foo
有效,但www.mysite.com/UA/
无效,则会发生重定向。在
上添加DirectorySlash并没有解决这个问题,我认为它已经打开了,因为这是默认设置。我接受了这个答案,因为@anubhava的评论帮助我解决了我的特殊问题;仍然好奇如何重定向非特定文件或目录请求。设置DirectoryIndex无效。
RewriteEngine on
ReWriteBase /UA/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|gif|woff|eot|ttf|svg|ico)$ [NC]
RewriteRule ^ index.php [L]