使用.htaccess使用sh404sef重定向Joomla上的剥离URL

时间:2011-11-26 03:02:45

标签: .htaccess mod-rewrite redirect joomla url-rewriting

在Joomla网站上工作,使用sh404sef将旧的结尾url.html更改为url /

但是我当然希望对旧的.html进行301重定向到新的,sh404sef不要这样做,我可以通过url做url但在这种情况下这不是一个选项。

一直在使用.htaccess尝试一切,但我不能让它工作,不知道是否有任何其他东西在.htaccess或sh404sef覆盖这个,需要一个解决方案。

这是htaccess

   RewriteEngine On

########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
#
########## End - Rewrite rules to block out some common exploits

#  Uncomment following line if your webserver's URL
#  is not directly related to physical file paths.
#  Update Your Joomla! Directory (just / for root)

# RewriteBase /



########## Begin - Joomla! core SEF Section
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://www.example.com/$1 [R=301,L]

########## End - Joomla! core SEF Section

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+).html$ $1/ [R=301,NC]
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.html

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1 [R=301,L]




php_flag display_errors off
php_flag register_globals off

php_value memory_limit 64M

所以澄清一切

是> http://www.website.com/page.html

现在是http://www.website.com/page/

当有人点击旧的.html网址时,他们会获得404并且会杀死访问者和搜索引擎优化。尝试了htaccess中的所有常用命令来执行此操作,但它不起作用。需要建议如何解决这个问题!

2 个答案:

答案 0 :(得分:0)

这样的东西 - 在其他规则之前 - 但在你第一次打开RewriteEngine

之后
RewriteCondition  %{REQUEST_FILENAME} !-f
RewriteRule (.*)\.html$ $1/ [R=301]

顺便说一句 - 您似乎有多个RewriteEngine On实例 - 这可能会导致某些服务器上出现服务器500错误。

答案 1 :(得分:0)

对我这样的工作:

Options +FollowSymLinks
RewriteEngine On

RewriteBase /yourfolderjoomla/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]