301通过.htcaccess重定向到/?page = home

时间:2016-05-13 16:25:23

标签: php .htaccess redirect

嘿伙计们,我无法弄清楚为什么我的重定向不起作用。试图将/ home和/ index重定向到主页面...这里是我的.htaccess上的内容。是否存在阻塞或导致此事的原因?

重定向301下的所有内容都是预审和&错误并且不确定我是否需要更改/删除任何内容。

我一直在尝试大量不同的东西,我只能获得500个内部服务器页面或/?page = home

redirect 301 /home http://example.com

Options -Indexes +FollowSymLinks
RewriteEngine on
RewriteBase /


RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ /$1 [R=301,L]

RewriteRule ^stats\/$ awstats/awstats.pl?config=www.example.com [R,L]
RewriteRule ^awstats\/$ awstats/awstats.pl?config=www.example.com [R,L]


# Redirect any requests for html files to index
RewriteRule ^(.+)\.html index.php?page=$1 [L]

# Rewrite any request for subdirectories to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?page=$1 [L,QSA]

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

1 个答案:

答案 0 :(得分:0)

请在问题中查看我的评论,然后尝试使用以下代码。希望代码注释和规则集的新顺序能够清楚地表明它应该如何工作。

Options -Indexes +FollowSymLinks -Multiviews

RewriteEngine on
RewriteBase /

# Remove "www."
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=302,L]

# Remove ".html"
RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*).html$ /$1 [R=302,L]

# Redirect "home" and "index" to document root
# > Here, the expression (home|index) means "home or index"
# > Trailing slash is optional
RewriteRule ^(home|index)/?$ / [R=302,L]

# Redirect "awstats" or "stats" to "awstats.pl"
# > The (aw)? makes "aw" optional
# > Trailing slash is optional
RewriteRule ^(aw)?stats/?$ awstats/awstats.pl?config=www.example.com [R=302,L]

# Rewrite any request for non-existing files to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?page=$1 [L,QSA]