gpt4 book ai didi

apache - .htaccess 在域文件夹中无法正确重定向

转载 作者:行者123 更新时间:2023-12-04 18:39:03 24 4
gpt4 key购买 nike

需要我的域名重定向

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
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>

注意:在我的文件系统中,这在 .htaccess 位于根目录 (root/.htaccess) 中时有效,但在域文件夹 (root/mydomain.com/.htaccess) 中时无法完全工作,我需要它在域文件夹中工作如果可能的话,因为主机会在域文件夹中自动生成一个 .htaccess 文件,这会弄乱根目录中的 .htaccess 文件。

谢谢你的帮助!

更新:2018 年 9 月 6 日

HostGator 似乎通读并更新了我的 .htaccess 文件并强制进行目录检查,我没有将此重定向添加到下面的 cpanel 检查图像中。

enter image description here
AddHandler application/x-httpd-php56 .php 
Options -MultiViews
RewriteBase /
RewriteEngine On
#redirect to https
RewriteCond %{HTTPS} Off
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R,L]
#end of https redirect

#Pretty url code
RewriteCond %{HTTP_HOST} ^(www\.)?6thsense.co$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteCond %{REQUEST_URI} !(\.$)
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule /([0-9a-zA-Z-_]+)/? /index.php?controller=$1 [NC,QSA,L]
#endof pretty url

#<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>

最佳答案

正确重写

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

关于apache - .htaccess 在域文件夹中无法正确重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52172587/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com