需要我的域重定向
FROM => mydomain.com/部分
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检查图像中。
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>
答案 0 :(得分:2)
正确重写
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
答案 1 :(得分:2)
您可以使用:
RewriteRule ([0-9a-zA-Z-_]+?)/?$ /index.php?controller=$1 [NC,QSA,L]
与mydomain.com/Section
和mydomain.com/Section/
一起使用的