Joomla から記事をインポートしました! IDを同じに保つK2に。今、私はJoomlaを書き直したいと思います! K2 アイテムを指す URL。SEF と modrewrite を有効にして Joomla 2.5.9 を使用しています。また、私は modrewrite ルールを使用したことがありません。何千もの記事や記事があるので、これが最良の選択肢だと思います。
変更したいURLは次のとおりです。
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) は考慮していません。
問題は次のとおりです: 書き換えルールで見逃したものは何ですか?
さらに、私は SO で見た他のルールを試しました。また、それらがどのように機能するかを理解しようとグーグルで調べましたが、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.