需要我的域名重定向
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。
谢谢你的帮助!
更新:2010年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>
您可以使用:
RewriteRule ([0-9a-zA-Z-_]+?)/?$ /index.php?controller=$1 [NC,QSA,L]
适用于mydomain.com/Section
和mydomain.com/Section/
正确的REWRITE
RewriteRule ([0-9a-zA-Z-_]+) /index.php?controller=$1 [NC,QSA,L]
#endof pretty url
不正确的REWRITE
RewriteRule /([0-9a-zA-Z-_]+)/? /index.php?controller=$1 [NC,QSA,L]
#endof pretty url