Mobile app version of vmapp.org
Login or Join
Phylliss660

: Redirect blog archive into certain format I asked the question in WPSE before, but the answer I got so far is a complicated one. I'm actually looking for a .htaccess way. Here's what the scenario

@Phylliss660

Posted in: #Htaccess #Url #UrlRewriting #Wordpress

I asked the question in WPSE before, but the answer I got so far is a complicated one. I'm actually looking for a .htaccess way. Here's what the scenario is:

My blog archive URLs were like:
example.com/2014/03

I changed my site's permalink from /%postname%/ to /%postid%/%postname%/, and using Redirection plugin, I set a redirection like:


and it's working. But the problem occurs in the archive URLs. The new archive URL generated with a /date/ basename before the dates, like:
example.com/date/2014/03

I'm trying to use the same Redirection plugin to redirect the URL, but failed:


I then tried writing .htaccess on my own (with no .htaccess writing experience) with:

Redirect permanent example.com/([0-9]+)/([0-9]+) example.com/date/([0-9]+)/([0-9]+)

with the help of htaccess editor and this blog. But failed too.

How can I let my blog not to get 404 on such archive URL? I'm afraid, I'm dumb with rewrite rule till now. :(

UPDATE

Here's how my .htaccess file just now:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress


And with Liam Sorsby's answer, I tried pasting the code

RewriteEngine on
RewriteRule ^([0-9]+)/([0-9]+)$ /date// [R=301,L]


just below the # END WordPress once, and then tried again just before # END WordPress. But both time failed.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Phylliss660

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ann8826881

I've had a quick test and this should do the trick:

RewriteEngine on
RewriteRule ^([0-9]+)/([0-9]+)$ /date// [R=301,L]


You may also need to exclude this from the redirect to the index.php page by adding

RewriteCond %{REQUEST_URI} !^/(date) [NC]


so it should look like this

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(date) [NC]
RewriteRule . /index.php [L]

RewriteRule ^([0-9]+)/([0-9]+)$ /date// [R=301,L]
</IfModule>
# END WordPress

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme