.htaccess
如果不是实际文件或文件夹,我将使用以下内容将所有URL重写为index.php文件:
Options +FollowSymLinks
RewriteEngine On
// This bit redirect www.mydomain.com to mydomain.com
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
// This bit redirects all requests to index.php if a file or directory
// bearing that name doesn't exist
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^.*$ ./index.php
我现在admin
要在我的网站上添加一个部分,并且我不想重写这个特定的URL:
mydomain.com/admin
我希望将这种情况视为默认情况下(在这种情况下,默认情况下为mydomain.com/admin/index.php
)
我试图自己解决这个问题,但regex
对我还是陌生的。
您可以使用:
Options +FollowSymLinks
RewriteEngine On
// This bit redirect www.mydomain.com to mydomain.com
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L,NE]
// This bit redirects all requests to index.php if a file or directory
// bearing that name doesn't exist OR it doesn't start with /admin/
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule !^admin/ ./index.php [L,NC]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句