Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess:non-www-to-www+无扩展URL+无索引_.htaccess_Redirect_Mod Rewrite_Url Rewriting - Fatal编程技术网

.htaccess:non-www-to-www+无扩展URL+无索引

.htaccess:non-www-to-www+无扩展URL+无索引,.htaccess,redirect,mod-rewrite,url-rewriting,.htaccess,Redirect,Mod Rewrite,Url Rewriting,我本以为这会更好地记录在某个地方,但找不到关于这个主题的太多信息 基本上,我正在使用htaccess向我正在工作的站点灌输3条规则: 将非www重定向/重写到www 从每个站点页面中删除扩展名——它们是php文件。这样做意味着站点索引将变成www.example.co.uk/index,而不是www.example.co.uk/index.php,因此。。。 将www.example.co.uk/index重定向/重写到www.example.co.uk/ 这是我从各种来源编译的脚本,它确实有效

我本以为这会更好地记录在某个地方,但找不到关于这个主题的太多信息

基本上,我正在使用htaccess向我正在工作的站点灌输3条规则:

将非www重定向/重写到www 从每个站点页面中删除扩展名——它们是php文件。这样做意味着站点索引将变成www.example.co.uk/index,而不是www.example.co.uk/index.php,因此。。。 将www.example.co.uk/index重定向/重写到www.example.co.uk/ 这是我从各种来源编译的脚本,它确实有效,但当我指向站点地图中的无扩展URL时,google似乎没有在站点上爬行,知道为什么吗?提前谢谢

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]
试试这些规则:

# 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]

那问题是什么?如果你想知道谷歌为什么不抓取这个网站,谷歌的抓取规则是由谷歌制定的——如果它不起作用,它就不起作用。问题是我是否犯了任何明显的错误,这会阻止它被正确抓取。。对不起,我应该说得更清楚。。就像我说的,规则的组合没有很好的文档记录。干杯谢谢你的意见。。我被抛出了一个500内部服务器错误,我确实将最后一行的L,R0301也更改为L,R=301。。此外,我还遗漏了一些我一直在使用的代码,现在我将这些代码添加到我的原始帖子中