2012-02-13 171 views
4

我最近使用htaccess更改了我的网址,以便我的网址不会显示文件扩展名。现在我的问题是因为我已经创建了一个新的XML网站地图,以便我的网址将无延展!谷歌网站管理员工具告诉我重复的内容问题!即。页面和page.html有相同的标题....所以我的问题是我如何重定向的URL与文件扩展名的URL到扩展名的URL! 这是我的网站的网址与HTML扩展名的例子将带有html扩展名的文件重定向到无扩展名的文件(在url中)

http://www.shenazhpeyk.co.uk/coding-machines.html

我想重定向,并更改为

http://www.shenazhpeyk.co.uk/coding-machines

,这样将解决与谷歌网站管理员工具的问题(请给我一个在htaccess文件中使用的代码)

很多谢谢

+0

另请参阅http://stackoverflow.com/questions/9250356/how-to-redirect-file-php-to-file-but-make-file-point-to-file-php/9250387 – Gerben 2012-02-13 15:01:14

回答

0

尝试将以下内容添加到网站根目录中的.htaccess文件中,并使用.html扩展名重定向网址并将其删除。

RewriteEngine on 
RewriteBase/

#redirect to remove the .html extension 
RewriteRule ^(.+)\.html$ $1 [L,NC,R=301] 
+0

感谢您的回复但我得到以下错误:页面无法正常重定向这是我从之前已经和它的工作原理,但它不会重定向HTML页面未扩展那些RewriteEngine叙述在 的RewriteCond%{} REQUEST_FILENAME -f 重写规则^! ([^ \。] +)$ $ 1.html [NC,L] – 2012-02-13 17:10:23

+0

耶!找到解决方案! – 2012-02-13 17:29:51

+2

我找到了解决方案,以防其他人遇到同样的问题!大声笑! 选项+了FollowSymLinks -MultiViews DirectorySlash关 RewriteEngine叙述在 的RewriteCond%{SCRIPT_FILENAME}/-d 的RewriteCond%{SCRIPT_FILENAME} .HTML!-f 重写规则[^ /] $%{REQUEST_URI}/[R = 301 ,L] 的RewriteCond%:(+)。{ENV REDIRECT_STATUS}^$ 重写规则^ \ HTML $/$ 1 [R = 301,L] 的RewriteCond%{SCRIPT_FILENAME} html的-f 重写规则[^/] $%{REQUEST_URI}的.html [QSA,L] 注:不知道这是否是正确的,但它的工程! – 2012-02-13 17:34:36

1

试试这个:

Options +FollowSymLinks -MultiViews 
DirectorySlash Off 

RewriteEngine On 

RewriteCond %{SCRIPT_FILENAME}/ -d 
RewriteCond %{SCRIPT_FILENAME}.html !-f 
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L] 

RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
RewriteRule ^(.+)\.html$ /$1 [R=301,L] 

RewriteCond %{SCRIPT_FILENAME}.html -f 
RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L] 
1

发现这个代码。不知道它是否会完成同样的事情。似乎为我工作,就像上面的那个(对于PHP)。

RewriteEngine On 

# Unless directory, remove trailing slash 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/$ /$1 [R=301,L] 

# Redirect external .php requests to extensionless url 
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/ 
RewriteRule ^(.+)\.php$ /$1 [R=301,L] 

# Resolve .php file for extensionless php urls 
RewriteRule ^([^/.]+)$ $1.php [L] 

我想知道后面的斜杠是否应该在那里或省略?

+0

我知道,我是一个迟到了,但你可以请你如何将它重定向到没有文件扩展名的页面?我真的很喜欢你的代码,现在正在使用它。 – 2016-10-04 02:27:38