Htaccess 重定向到 home 作为 / 但将 .index.asp 保留在目录上
我需要有关 htaccess 文件的帮助:
Options -Indexes
Options +FollowSymLinks
DirectoryIndex index.html index.htm index.asp index.php
ErrorDocument 401 http://www.domainname.com
ErrorDocument 403 http://www.domainname.com
ErrorDocument 404 http://www.domainname.com
ErrorDocument 500 http://www.domainname.com
ErrorDocument 507 http://www.domainname.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domainname.com$
RewriteRule ^(.*) http://domainname.com/$1 [QSA,L,R]
RewriteRule ^(.*/)?index\.([a-zA-Z0-9]{3,4})$ /$1 [R=301,L]
RewriteRule ^(.*)\.htm$ $1.php [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index1.php?/$1 [L]
AddType text/html .html .htm .asp
AddType text/css .css
AddType image/vnd.microsoft.icon .ico
AddType image/jpeg .jpg
ExpiresActive on
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType image/vnd.microsoft.icon "access plus 3 months"
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>
# compress the files
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript
# removes some bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
我的 htaccess 文件中有此行 RewriteRule ^(.*/)?index\.([a-zA-Z0-9]{3,4})$ /$1 [R=301,L]
目前,它会将我对索引文件的任何访问定向到该文件的根目录,以便点击
http://www.domainname.com/index.asp 将变为 http:// /www.domainname.com/ 这正是我想要的。但是,如果域名位于带有索引文件的子文件夹上,它将仅显示目录,而不显示页面名称: http://www.domainname.com/folder1/folder2/index.asp 将变为 http://www.domainname.com/folder1/folder2/ 这不是我想要的。
如何修复它,以便 RewriteRule ^(.*/)?index\.([a-zA-Z0-9]{3,4})$ /$1 [R=301,L]
仅当在 http://www.domainname.com/index.html 上点击时才会将其重定向到根目录。 asp 并且并非在所有目录上。
谢谢!
I need some help with an htaccess file:
Options -Indexes
Options +FollowSymLinks
DirectoryIndex index.html index.htm index.asp index.php
ErrorDocument 401 http://www.domainname.com
ErrorDocument 403 http://www.domainname.com
ErrorDocument 404 http://www.domainname.com
ErrorDocument 500 http://www.domainname.com
ErrorDocument 507 http://www.domainname.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domainname.com$
RewriteRule ^(.*) http://domainname.com/$1 [QSA,L,R]
RewriteRule ^(.*/)?index\.([a-zA-Z0-9]{3,4})$ /$1 [R=301,L]
RewriteRule ^(.*)\.htm$ $1.php [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index1.php?/$1 [L]
AddType text/html .html .htm .asp
AddType text/css .css
AddType image/vnd.microsoft.icon .ico
AddType image/jpeg .jpg
ExpiresActive on
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType image/vnd.microsoft.icon "access plus 3 months"
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>
# compress the files
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript
# removes some bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
I have this line in my htaccess file RewriteRule ^(.*/)?index\.([a-zA-Z0-9]{3,4})$ /$1 [R=301,L]
at the moment it will direct any visit I receive on a index file to the root of that file so a hit on
http://www.domainname.com/index.asp will become http://www.domainname.com/ which is exactly what I want. However if the domain is hit on a subfolder with an index file it will only show the directory and not the page name as well: http://www.domainname.com/folder1/folder2/index.asp will become http://www.domainname.com/folder1/folder2/ which is not what I want.
How do I fix it so that RewriteRule ^(.*/)?index\.([a-zA-Z0-9]{3,4})$ /$1 [R=301,L]
will only redirect the to the root if it is hit on http://www.domainname.com/index.asp and not on all directories.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
重写规则正则表达式的第一部分是匹配 / (或不)之前的任何内容。我们可以删除该部分并使其在根目录下生效。
The first part of your rewrite rule regex is matching anything up to a / (or not). We can remove that part and just have it take effect on the root directory.