Apache .htaccess在域文件夹中时未正确重定向
需要我的域名重定向吗 FROM=>mydomain.com/Section TO=>mydomain/index.php?controller=Section 我希望用户如何查看URL=>mydomain.com/Section 这是我写的.htaccess文件Apache .htaccess在域文件夹中时未正确重定向,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,需要我的域名重定向吗 FROM=>mydomain.com/Section TO=>mydomain/index.php?controller=Section 我希望用户如何查看URL=>mydomain.com/Section 这是我写的.htaccess文件 AddHandler application/x-httpd-php56 .php DirectoryIndex index.php RewriteEngine on RewriteCond %{HTTPS} off RewriteRu
AddHandler application/x-httpd-php56 .php
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
# above code does work at least the https redirect but below wont
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteCond %{REQUEST_URI} !(\.$)
RewriteRule /([0-9a-zA-Z-_]+)/? index.php?controller=$1 [NC,QSA,L]
<filesmatch "\.(html|htm|js|css)$"="">
FileETag None
<ifmodule mod_headers.c="">
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifmodule>
</filesmatch>
AddHandler应用程序/x-httpd-php56.php
DirectoryIndex.php
重新启动发动机
重写条件%{HTTPS}关闭
重写规则(.*)https://%{HTTP_HOST}%{REQUEST_URI}[R,L]
#上面的代码至少在https重定向中有效,但下面的代码无效
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
1美元^(索引\.php | robots\.txt)
重写cond%{REQUEST_URI}!(\.$)
重写规则/([0-9a-zA-Z-100;]+)/?php?控制器=$1[NC,QSA,L]
FileTag无
标题未设置ETag
标题集缓存控制“最大年龄=0,无缓存,无存储,必须重新验证”
标题集Pragma“无缓存”
标题集过期“1984年1月11日星期三05:00:00 GMT”
注意:在我的文件系统中,当.htaccess在根目录(root/.htaccess)中时,它可以工作,但在域文件夹(root/mydomain.com/.htaccess)中时,它不能完全工作。如果可能的话,我需要它在域文件夹中工作,因为主机会在域文件夹中自动生成一个.htaccess文件,这会扰乱根目录中的.htaccess 谢谢你的帮助 更新:2018年9月6日 看来HostGator读取并更新了我的.htaccess文件,并且正在强制进行目录检查,我没有将此重定向添加到下面的cpanel检查图像中
AddHandler应用程序/x-httpd-php56.php
选项-多视图
重写基/
重新启动发动机
#重定向到https
重写条件%{HTTPS}关闭
重写规则(.*)https://www.%{HTTP_HOST}%{REQUEST_URI}[R,L]
#https重定向结束
#漂亮的url代码
RewriteCond%{HTTP_HOST}^(www\)?6thsense.co$
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
1美元^(索引\.php | robots\.txt)
重写cond%{REQUEST_URI}!(\.$)
重写条件%{REQUEST\u URI}!^/\。著名的/acme挑战/[0-9a-zA-Z_-]+$
重写条件%{REQUEST\u URI}!^/\。知名/cpanel dcv/[0-9a-zA-Z_u-]+$
重写条件%{REQUEST\u URI}!^/\。众所周知的/pki验证/[A-F0-9]{32}\.txt(?:\comdo\DCV)?$
重写规则/([0-9a-zA-Z-100;]+)//php?控制器=$1[NC,QSA,L]
#结束漂亮的url
#
#FileTag无
#
#标题未设置ETag
#标题集缓存控制“最大年龄=0,无缓存,无存储,必须重新验证”
#标题集Pragma“无缓存”
#标题集过期“1984年1月11日星期三05:00:00 GMT”
#
#
正确重写
RewriteRule ([0-9a-zA-Z-_]+) /index.php?controller=$1 [NC,QSA,L]
#endof pretty url
RewriteRule /([0-9a-zA-Z-_]+)/? /index.php?controller=$1 [NC,QSA,L]
#endof pretty url
错误重写
RewriteRule ([0-9a-zA-Z-_]+) /index.php?controller=$1 [NC,QSA,L]
#endof pretty url
RewriteRule /([0-9a-zA-Z-_]+)/? /index.php?controller=$1 [NC,QSA,L]
#endof pretty url
您可以使用:
RewriteRule ([0-9a-zA-Z-_]+?)/?$ /index.php?controller=$1 [NC,QSA,L]
这适用于
mydomain.com/Section
和mydomain.com/Section/
“因为主机一直在域文件夹中自动生成一个.htaccess文件,这会扰乱根目录中的.htaccess”,这听起来像是问题所在。此自动生成过程是否有方法让您配置其他内容?是什么控制了这种自动生成?你能编辑吗?检查我的更新,自动生成是不可修改的,从我所看到的,它只允许我添加和删除重定向。Hostgator的帮助页面没有提到任何东西,将编辑文件后,你这样做:我想知道它是否是与它乱搞?我不是这方面的用户。我修复了它,hostgator确实更改了它,但这不是问题,重写规则写错了。不过我想问一个简单的问题,这是否适用于以下请求:mydomain.com/Section/?mario=cool to display:$\u GET=['controller'=>'Section','mario'=>'cool'],因为据我所知,$char表示urlIn重写规则的结束,测试url永远不会以/
开头!您可以使用RewriteRule^([0-9a-zA-Z-\]+)/?$/index.php?controller=$1[NC,QSA,L]