我从Joomla进口了我的物品!来保持ids不变的K2。现在我想重写Joomla!指向K2项的urls。我使用Joomla2.5.9与SEF和modrewrite。而且,我从来没有使用过modrewrite规则--我认为这是最好的选择,因为我有成千上万的文章或文章。
我想更改的网址是:
http://www.mysite.com/news/component/content/article/9-society/19771-the-alias-of-the-article
由同一个K2项生成的url是
http://www.mysite.com/news/society/19771-the-alias-of-the-article
我创建菜单项society是为了获得这个url。
因此,我编辑了.htaccess以创建如下规则
RewriteRule ^news/component/content/article/9-(.*)$ /news/$1 [R=301,L]但是我得到了一个404错误页面。请注意,此示例试图了解modrewrite是否有效。我还没有进入id类别(在本例中为9)。
问题是:重写规则让我错过了什么?
此外,我还尝试了其他规则,我在其中看到过,谷歌也试图了解它们是如何工作的,但也与404错误页面。这个问题中规定的规则是,据我所知,应该发挥神奇的作用。
在答案中建议修改的htaccess文件如下(我的站点在新闻文件夹中)。如果我使用RewriteBase,我需要调整它):
##
# @package Joomla
# ...
Options +FollowSymlinks -MultiViews
## Mod_rewrite in use.
RewriteEngine On
## Begin - Rewrite rules to block out some common exploits.
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*([^)]*) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%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})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.
## Begin - Custom redirects
# My site is in the news folder. If I use RewriteBase I need to adjust it
RewriteBase /news/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^news/component/content/article/9-([^/]+)/([^/]+)/? /news/$1/$2 [R=301,L]
## End - Custom redirects
##
# 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.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.发布于 2013-02-25 01:27:36
您可以在根目录中的一个.htaccess文件中尝试这样做:
更新了文件夹/news中的/news文件
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /news
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^component/content/article/9-([^/]+)/([^/]+)/? $1/$2 [R=301,L]重定向
带或不带尾斜杠的http://www.mysite.com/news/component/content/article/9-society/19771-the-alias-of-the-article
至
http://www.mysite.com/news/society/19771-the-alias-of-the-article
假定所有字符串都是固定的,但society和19771-the-alias-of-the-article除外。
对于静默映射,从R=301中删除[R=301,L]
注意:两个RewriteCond %{REQUEST_FILENAME}...都是用来防止循环的。它们检查文件或目录是否存在,以跳过规则以防止它们存在。
https://stackoverflow.com/questions/15054191
复制相似问题