質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
.htaccess

Apacheウェブサーバーにおいて、ディレクトリ単位で設置及び設定を行う設定ファイルを指します。

Q&A

解決済

1回答

428閲覧

連番のリダイレクトがうまくいかないです

QOOSO_PLAN

総合スコア12

.htaccess

Apacheウェブサーバーにおいて、ディレクトリ単位で設置及び設定を行う設定ファイルを指します。

0グッド

0クリップ

投稿2018/06/25 11:38

前提・実現したいこと

/gallery/design/bellipaint-design-3桁の連番/

/gallery/design/bellypaint-design-3桁の連番/

に301リダイレクトしたいのですが、うまくいきません。
bellypaint
の綴りを間違えました

発生している問題・エラーメッセージ

リダイレクト反応なし

該当のソースコード

RewriteEngine On RewriteRule ^/gallery/design/bellipaint-design-([0-9]{3})/ /gallery/design/bellypaint-design-$1/ [R=301,L]

試したこと

リダイレクトマッチでもやってみましたが、うまくいきません。

補足情報(FW/ツールのバージョンなど)

初歩的な質問で大変恐縮ですが、ご回答いただけますと幸いです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

http://localhost/gallery/design/bellipaint-design-123/ のようなURLでアクセスした場合、RewriteRuleでは gallery/design/bellipaint-design-123/ をチェックするので、最初の / が不要ですね。

RewriteRule ^gallery/design/bellipaint-design-([0-9]{3})/$ gallery/design/bellypaint-design-$1/ [R=301,L]

投稿2018/06/25 12:34

mather

総合スコア6753

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

QOOSO_PLAN

2018/06/26 00:12

早速ありがとうございました! また、ご丁寧に回答いただき感謝申し上げます。 そのあと、設定してみましたが、下記のようなアドレスにリダイレクトされました。 https://www.heartkoru.com/home/heartkoru/heartkoru.com/public_html/gallery/design/bellypaint-design-001/ RewriteBase / と設定してみましたが、特に変化もありませんでした。 こちらについては私の設定方法が間違っているのでしょうか。 ご教授いただけますと幸いです。
mather

2018/06/26 01:26

/home/heartkoru/heartkoru.com/public_html の部分は絶対パスがそのまま表示されてますよね。 具体的にどんな設定をしているのか全体像が見えないのでなんとも言えませんが、RewriteBaseの行をコメントアウトまたは削除してみてください。
QOOSO_PLAN

2018/06/26 03:13

ありがとうございます。 削除しても変わらないみたいです。 一応、.設定内容を全て記載します。 ご丁寧に返信いただいているのに、すみません。。 下記のように記述しているのですが、 そもそもの記述方法が間違っているのでしょうか。 ※ちなみにサーバーはエックスサーバーです ご返信お願いして恐縮ですが、ご確認いただけますと大変助かります。。 ---------------------------------------------- Options +FollowSymLinks AddDefaultCharset utf-8 #www有りに正規化 RewriteEngine on RewriteCond %{HTTP_HOST} ^(heartkoru.com)(:80)? [NC] RewriteRule ^(.*) https://www.heartkoru.com/$1 [R=301,L] #index.htmlなしに正規化 RewriteEngine on RewriteCond %{THE_REQUEST} ^.*/index.html RewriteRule ^(.*)index.html$ https://www.heartkoru.com/$1 [R=301,L] #SSLリダイレクト RewriteEngine on RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] #404ページへの誘導 ErrorDocument 404 /404.html RewriteEngine On RewriteCond %{QUERY_STRING} lightbox= RewriteRule ^/gallery/? [R=301,L] RewriteEngine On RewriteRule ^gallery/design/bellipaint-design-([0-9]{3})/$ gallery/design/bellypaint-design-$1/ [R=301,L] #ページ単位の301 Redirect permanent /princess https://www.heartkoru.com/bellypaint-menu/princess/ Redirect permanent /babyphoto-1 https://www.heartkoru.com/mother/baby-photo/ Redirect permanent /maternitypaint-design?lightbox=image_1ssd https://www.heartkoru.com/gallery/ Redirect permanent /maternity-photo https://www.heartkoru.com/bellypaint-menu/maternity-photo/ Redirect permanent /bellypaint https://www.heartkoru.com/bellypaint-menu/ Redirect permanent /maternitypaint-design https://www.heartkoru.com/gallery/ Redirect permanent /aboutus https://www.heartkoru.com/about/ Redirect permanent /babyphoto https://www.heartkoru.com/mother/breastfeeding/ Redirect permanent /bellypaint-memo https://www.heartkoru.com/about/ Redirect permanent /blank https://www.heartkoru.com/copyright/ Redirect permanent /blank-1 https://www.heartkoru.com/gift/ Redirect permanent /maori https://www.heartkoru.com/bellypaint-menu/maori/ Redirect permanent /staff https://www.heartkoru.com/about/ Redirect permanent /menu3 https://www.heartkoru.com/faq/ Redirect permanent /menu1 https://www.heartkoru.com/about/ Redirect permanent /company https://www.heartkoru.com/about/ Redirect permanent /staff-1 https://www.heartkoru.com/about/ Redirect permanent /maternitypaint-design https://www.heartkoru.com/gallery/ Redirect permanent /petit-flower https://www.heartkoru.com/bellypaint-menu/petit-flower/ Redirect permanent /originalgoods https://www.heartkoru.com/gift/ Redirect permanent /trial https://www.heartkoru.com/bellypaint-menu/trial/ Redirect permanent /decoart https://www.heartkoru.com/bellypaint-menu/ Redirect permanent /#!bellypaint-menu/ https://www.heartkoru.com/bellypaint-menu/ Redirect permanent /gallery/?lightbox=dataItem-j2qspwgr https://www.heartkoru.com/gallery/ Redirect permanent /gallery/?lightbox=dataItem-it14z4i8 https://www.heartkoru.com/gallery/ #gzip圧縮 <IfModule mod_deflate.c> SetOutputFilter DEFLATE BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4.0[678] no-gzip BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png|ico)$ no-gzip dont-vary SetEnvIfNoCase Request_URI _.utxt$ no-gzip #DeflateCompressionLevel 4 AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/atom_xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE application/x-httpd-php AddOutputFilterByType DEFLATE application/x-font AddOutputFilterByType DEFLATE application/x-font-opentype AddOutputFilterByType DEFLATE application/x-font-otf AddOutputFilterByType DEFLATE application/x-font-truetype AddOutputFilterByType DEFLATE application/x-font-ttf </IfModule> SetEnvIf Request_URI ".*" AllowCountry
mather

2018/06/26 05:01

記載内容からはこれといってはっきりした原因はわからないですね。 httpd.confや .htaccessのRewrite関連の記載はこれで全部ですか?
QOOSO_PLAN

2018/06/26 11:57

返信遅くなり失礼しました。 /column配下にWorpressの .htaccessがありますが、こちらは関係してきますでしょうか・・・? ---------------------------------------------- # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /column/ RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /column/index.php [L] </IfModule> # END WordPress
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問