HTAccess如果URL看起来像Root,则重写

时间:2015-02-05 20:27:22

标签: .htaccess mod-rewrite

嗨一直在寻找年龄并尝试了一些例子,但没有任何工作。我希望我的网址看起来好像位于根目录而不是购买子目录中:

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

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

RewriteRule ^buy/(.*)$ $1 [L]

继续使页面无法正确重定向。 @Panama Jack

感谢任何想法。

的.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

1 个答案:

答案 0 :(得分:0)

如果/buy/somepage.html是真实页面,那么如果您需要

,请尝试这种方式
  

http://www.example.com/page.html

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