2010-09-17 68 views
0

我原以为这会更好地记录在某处,但无法找到有关该主题的许多信息。.htaccess:非www到www +不扩展网址+没有索引

基本上我使用htaccess的在网站上灌输3条规则我的工作:

  1. 重定向/重写非www到www
  2. 从每个网站的网页的删除扩展 - 他们是PHP文件。这意味着网站索引变成www.example.co.uk/index而不是www.example.co.uk/index.php,所以...
  3. 重定向/重写www.example.co.uk/指数www.example.co.uk/

这是我从各种来源编译脚本,它的工作,但谷歌似乎并不当我指向的扩展名被抓取网站在网站地图的网址,任何想法为什么?提前致谢。

Options +FollowSymlinks 
RewriteEngine On 

# Rewrite index.php to/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/#?\ ]+/)*index\.php?\ HTTP/ 
RewriteCond %{HTTP_HOST} ^(www\.example\.co\.uk) [OR] 
RewriteCond www.%{HTTP_HOST} ^(www\.example\.co\.uk) 
RewriteRule ^(([^/]+/)*)index\.php?$ http://%1/$1 [R=301,L] 

# Rewrite example.co.uk to www.example.co.uk for canonic purposes, this rule is paired with the previous 
RewriteCond %{HTTP_HOST} ^example\.co\.uk [NC] 
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [R=301,L] 
#REMOVE .php from file extensions 
# If the requested URI does not contain a period in the final path-part 
RewriteCond %{REQUEST_URI} !(\.[^./]+)$ 
# and if it does not exist as a directory 
RewriteCond %{REQUEST_fileNAME} !-d 
# and if it does not exist as a file 
RewriteCond %{REQUEST_fileNAME} !-f 
# then add .php to get the actual filename 
RewriteRule (.*) /$1.php [L] 

# If client request header contains php file extension 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php\ HTTP 
# externally redirect to extensionless URI 
RewriteRule ^(.+)\.php$ http://www.example.co.uk/$1 [R=301,L] 
+0

有什么问题呢?如果您想知道Google为什么不抓取该网站,Google的抓取规则是由Google组成的 - 如果它不起作用,则不起作用。 – Rushyo 2010-09-17 13:20:48

+0

问题是,如果我有任何明显的错误,我会阻止它被正确抓取..对不起,我应该已经做得更清楚了..就像我说的规则组合很少记录。干杯 – Storsey 2010-09-17 13:26:53

回答

0

尝试下列规则:

# Redirect/rewrite non-www to www 
RewriteCond %{HTTP_HOST} ^www\.(.+) 
RewriteCond %{HTTPS}s://%1 ^on(.+)|offs(.+ 
RewriteRule^http%1%2%{REQUEST_URI} [L,R=301] 

# Remove the extensions from each of the site pages - they're php files. Doing this means that the site index becomes www.site.com/index instead of www.site.com/index.php, so... 
RewriteCond %{THE_REQUEST} ^GET\ (/[^?\ ]+)\.php[?\ ] 
RewriteRule .+\.php$ %1 [L,R=301] 

#Redirect/rewrite the www.site.com/index to www.site.com/ 
RewriteRule ^index$/[L,R=301] 
+0

感谢您的输入..我得到了一个500内部服务器错误(我没有改变L,R0301的最后一行L,R = 301也)..我也遗漏了一些我已经使用,我将只添加到我原来的帖子 – Storsey 2010-09-17 13:59:58