.htaccess HTAccess将URL重写为类似于根目录

.htaccess HTAccess将URL重写为类似于根目录,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,他已经搜索了很多年,尝试了一些例子,但没有任何效果。我希望我的URL看起来好像位于根目录而不是buy子目录中: http://www.example.com/buy/*.html 到 继续获取未正确重定向的页面@巴拿马杰克 有什么想法吗,谢谢 .HTACCESS # non-www to www RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com$ RewriteRule (.*) http://www.example.com/$1

他已经搜索了很多年,尝试了一些例子,但没有任何效果。我希望我的URL看起来好像位于根目录而不是buy子目录中:

http://www.example.com/buy/*.html

继续获取未正确重定向的页面@巴拿马杰克

有什么想法吗,谢谢

.HTACCESS

# non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]


AddType application/x-httpd-php .html .htm


# rewrite products to root located    
RewriteRule ^buy/(.*)$ $1 [L]


# Remove index.php or index.htm/html from URL requests
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.(php|html?)\ HTTP/
RewriteRule ^([^/]+/)*index\.(html?|php)$ http://www.example.com/$1 [R=301,L]


# GZIP
AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css application/x-javascript application/javascript


# Redirect all index calls
RewriteEngine On
RewriteRule ^index\.(php|html?)$ http://www.example.com/ [R=301,L]


#Custom 404 errors
ErrorDocument 404 /productslinks404.html

如果
/buy/somepage.html
是一个真实的页面,那么如果您愿意,可以这样尝试您的规则


谢谢你的回复。我对商店本身的动态url进行了另一次重写,现在当我进入www.example,com/new.html,即www.example.com/buy/buy/buy/buy/buy/buy/buy/buy/buy/buy/buy/buy/buy/buy/buy/buy/new.htmlWhat是你所有的规则?编辑您的问题并添加htaccess文件的内容,而不仅仅是其中的一部分。@巴拿马更新了我的问题。谢谢你抽出时间。
# non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]


AddType application/x-httpd-php .html .htm


# rewrite products to root located    
RewriteRule ^buy/(.*)$ $1 [L]


# Remove index.php or index.htm/html from URL requests
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.(php|html?)\ HTTP/
RewriteRule ^([^/]+/)*index\.(html?|php)$ http://www.example.com/$1 [R=301,L]


# GZIP
AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css application/x-javascript application/javascript


# Redirect all index calls
RewriteEngine On
RewriteRule ^index\.(php|html?)$ http://www.example.com/ [R=301,L]


#Custom 404 errors
ErrorDocument 404 /productslinks404.html
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*).html$ /buy/$1.html [L]