1

I have .htaccess file with redirect 301 on it and placed right under the rewriteengine

<IfModule mod_rewrite.c>
RewriteEngine On
#now this is the redirect
Redirect 301 /blog.php?slug=konsolidasi-tanah-frequently-asked-questions https://jpi.or.id/blog/2021/02/11/pengertian-konsolidasi-tanah

Redirect 301 /blog/2021/02/11/konsolidasi-tanah-frequently-asked-questions https://jpi.or.id/blog/2021/02/11/pengertian-konsolidasi-tanah

</IfModule>

only 2nd redirect works, the one with the get method are not redirected, am i doing wrong?

EDITED :

this is my entire mod rewrite :

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^index\.php$ / [R=301,L]
RewriteRule ^(.*)/index\.php$ /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
# Permanent URL redirect
Redirect 301 /blog.php?slug=konsolidasi-tanah-frequently-asked-questions https://jpi.or.id/blog/2021/02/11/pengertian-konsolidasi-tanah
# Permanent URL redirect
Redirect 301 /blog/2021/02/11/konsolidasi-tanah-frequently-asked-questions https://jpi.or.id/blog/2021/02/11/pengertian-konsolidasi-tanah

Redirect 301 /blog.php?slug=konsolidasi-tanah-frequently-asked-questions /blog/2021/02/11/pengertian-konsolidasi-tanah
RewriteRule ^blog/2021/02/11/pengertian-konsolidasi-tanah   /blog.php?slug=konsolidasi-tanah-frequently-asked-questions
  • The `Redirect` directive matches against the _path_ component of the URL only, you can not use it to check on query string contents. You will need to use mod_rewrite for that, a combination of RewriteCond and RewriteRule. – CBroe Mar 09 '22 at 14:50
  • @CBroe how can i use mod_rewrite combination without override my other rewrite link?, can i use multiple mod_rewrite tag? – Gusde Widnyana Mar 09 '22 at 14:58
  • A "mod_rewrite tag" is not a thing. Multiple RewriteConds and RewriteRules can be used, of course. If you are completely new to the matter, then perhaps start with https://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained for some basics. – CBroe Mar 09 '22 at 15:02
  • Can you tell us what your other rewrite rules are? It is hard to tell you how they might conflict without seeing them. – Stephen Ostermiller Mar 09 '22 at 16:35
  • @StephenOstermiller i edited my post to see the entire Mod rewrite that i have – Gusde Widnyana Mar 10 '22 at 03:21

1 Answers1

0

It is usually not a good idea to mix RewriteRule and Redirect 301 directives. They can conflict with each other in unexpected ways. You depend of RewriteRule so you should implement your redirects with more of them.

Redirect 301 can't redirect based on query strings (?...) in the URL, so you need to implement RewriteRules for that redirect anyway.

When you have rules for redirecting specific URLs, they should go at the top of the .htaccess file so that they take precedence over the other more general rules.

I would recommend disabling the directory index because I fear it would conflict with your RewriteRule ^index\.php$ / [R=301,L] rule.

I don't see RewriteEngine On in your .htaccess file, despite that your snippet you posted to start with has it.

Try this as your .htaccess:

# Disable index.html, index.php default functionality
DirectoryIndex disabled

RewriteEngine On

# Permanent URL redirect
RewriteCond %{QUERY_STRING} ^slug=konsolidasi-tanah-frequently-asked-questions$
RewriteRule ^blog\.php$ https://jpi.or.id/blog/2021/02/11/pengertian-konsolidasi-tanah [R=301,L]

RewriteRule ^blog/2021/02/11/konsolidasi-tanah-frequently-asked-questions$ https://jpi.or.id/blog/2021/02/11/pengertian-konsolidasi-tanah  [R=301,L]

# Forward URLs without .php extension to existing PHP file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php

# Redirect index.php URLs to the directory
RewriteRule ^index\.php$ / [R=301,L]
RewriteRule ^(.*)/index\.php$ /$1/ [R=301,L]

# Use index.php as a front controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109