的.htaccess:非www到www +扩展名的URL +没有索引 [英] .htaccess: non-www to www + extensionless urls + no index

查看:180
本文介绍了的.htaccess:非www到www +扩展名的URL +没有索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还以为这会在某处得到更好的记录,却找不到关于这个问题的信息。

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

  1. 在重定向/重写非www到www
  2. 从每个网站的网页中删除的扩展 - 他们是PHP文件。这样做意味着站点索引变得www.example.co.uk/index~~V代替www.example.co.uk/index.php,所以...
  3. 在重定向/重写www.example.co.uk/index到www.example.co.uk/~~V

这是我从各种来源编译脚本,它的工作,但谷歌似乎并没有被抓取网站时,我指向扩展名的URL在Sitemap ,任何想法为什么?先谢谢了。

 选项+了FollowSymLinks
RewriteEngine叙述上

#重写的index.php到/
的RewriteCond%{THE_REQUEST} ^ [AZ] {3,9} \ /([^ /#?\] + /)*指数\的.php?\ HTTP /
的RewriteCond%{HTTP_HOST} ^(WWW \ .EXAMPLE \ .CO \。英国)[OR]
WWW的RewriteCond%{HTTP_HOST} ^(WWW \ .EXAMPLE \ .CO \。英国)
重写规则^(([^ /] + /)*)指数\ .PHP $ HTTP://%1 / $ 1 [R = 301,L]

#重写example.co.uk到www.example.co.uk的法服的目的,这个规则是搭配了previous
的RewriteCond%{HTTP_HOST} ^例如\ .CO \ .UK [NC]
重写规则^(。*)$ http://www.example.co.uk/$1 [R = 301,L]
从文件扩展名#REMOVE的.php
#如果所请求的URI不包含在最终路径的部分期间
的RewriteCond%{REQUEST_URI}!(\。[^​​ /] +)$
#和如果它不存在,作为一个目录
的RewriteCond%{} REQUEST_FILENAME!-d
#,如果它不存在,作为一个文件
的RewriteCond%{} REQUEST_FILENAME!-f
#再加入.PHP获得的实际文件名
重写规则(。*)/$1.php [L]

#如果客户端请求头中包含的PHP文件的扩展名
的RewriteCond%{THE_REQUEST} ^ [AZ] {3,9} \ /([^.]+\.)+ PHP \ HTTP
#外部重定向到无扩展名的URI
重写规则^(。+)\。PHP $ http://www.example.co.uk/$1 [R = 301,L]
 

解决方案

请尝试以下规则:

 #重定向/重写非www到www
的RewriteCond%{HTTP_HOST} ^ WWW \。(。+)
的RewriteCond%{} HTTPS S:(+)。//%1 ^开|取舍(+
重写规则^的http%1%2%{REQUEST_URI} [L,R = 301]

#从每个网站的网页中删除的扩展 - 他们是PHP文件。这样做意味着站点索引变得www.site.com/index~~V代替www.site.com/index.php,所以...
的RewriteCond%{THE_REQUEST} ^ GET \(/ [^ \] +)\。PHP [?\]
重写规则+ \ PHP $%1 [L,R = 301]

#REDIRECT /重写www.site.com/index到www.site.com/~~V
重写规则^指数$ / [L,R = 301]
 

I would have thought this would be better documented somewhere, but cannot find much information on the subject.

Basically I'm using htaccess to instill 3 rules on the site i'm working on:

  1. Redirect / rewrite non-www to www
  2. Remove the extensions from each of the site pages - they're php files. Doing this means that the site index becomes www.example.co.uk/index instead of www.example.co.uk/index.php, so...
  3. Redirect / rewrite the www.example.co.uk/index to www.example.co.uk/

This is the script I've compiled from various sources, it does work, but google doesn't seem to be crawling the site when i point to the extensionless urls in the sitemap, any idea why? Thanks in advance.

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]

解决方案

Try these rules:

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

这篇关于的.htaccess:非www到www +扩展名的URL +没有索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆