Forum

Thread tagged as: Question, Blog

Need help rewritng Author Urls

Hello,

I'm having som trouble rewriting urls for my authors my current rewrite code is below:

RewriteRule ^blog/([a-zA-Z0-9-/]+)/archive.php?s=$1$ /blog/archive.php?author=$1&page=$2 [L]
RewriteRule ^blog/([a-zA-Z0-9-/]+)/archive.php?s=$1$ /blog/archive.php?author=$1 [L]

Here's how it currently looks:

https://www.zurimagazine.com/blog/06/10/15/archive.php?author=zuri-magazine

and here's what i'd like:

https://www.zurimagazine.com/author/zuri-magazine

can anyone help?

Nathaniel Nwosu

Nathaniel Nwosu 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

RewriteRule ^author/([a-zA-Z0-9-/]+)$ /blog/archive.php?author=$1 [L]

Hi Drew,

It doesn't seem to be working, i'm starting to think i gave you the wrong information. My current .htaccess file is below:

SetEnv PHPRC /home/zurimaga/public_html/php.ini
<IfModule mod_rewrite.c>  
    RewriteEngine on 

    RewriteRule ^blog/([a-zA-Z0-9-/]+)/preview$ /blog/post.php?s=$1&preview=all [L]
    RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1 [L]

    RewriteRule ^blog/category/([a-zA-Z0-9-/]+)/page/([0-9]+)/{0,1}$ /blog/archive.php?cat=$1&page=$2 [L]
    RewriteRule ^blog/category/([a-zA-Z0-9-/]+)$ /blog/archive.php?cat=$1 [L]

    RewriteRule ^author/([a-zA-Z0-9-/]+)$ /blog/archive.php?author=$1 [L]

    # /blog/06/10/15/archive.php?author=zuri-magazine

    RewriteRule ^blog/date/([a-zA-Z0-9-/]+)/page/([0-9]+)/{0,1}$ /blog/archive.php?year=$1&page=$2 [L]
    RewriteRule ^blog/date/([a-zA-Z0-9-/]+)$ /blog/archive.php?year=$1 [L]

    RewriteRule ^blog/tag/([a-zA-Z0-9-/]+)/page/([0-9]+)/{0,1}$ /blog/archive.php?tag=$1&page=$2 [L]
    RewriteRule ^blog/tag/([a-zA-Z0-9-/]+)$ /blog/archive.php?tag=$1 [L]

    # Redirect to PHP if it exists.
    # e.g. example.com/foo will display the contents of example.com/foo.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f 
    RewriteRule ^(.+)$ $1.php [L,QSA]

</IfModule>


SetEnv TZ Europe/London

#Gzip
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript image/svg+xml
</ifmodule>
#End Gzip


## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/js "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##

Here's what a typical blog url looks like on my site:

https://zurimagazine.com/blog/11/10/15/help-which-essential-oil-do-i-use-on-my-natural-hair

So i'm guessing with the right line in my .htaccess file, the author link should look like this:

https://www.zurimagazine.com/blog/author/zuri-magazine

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so:

RewriteRule ^blog/author/([a-zA-Z0-9-/]+)$ /blog/archive.php?author=$1 [L]

Hi Drew,

The snippet you sent over didn't work so i done a little trial and error and got it doing something. My url now looks like this:

https://www.zurimagazine.com/blog/archive.php?author=zuri-magazine

using this line in my .htaccess:

RewriteRule ^blog/([a-zA-Z0-9-/]+)/author$ /blog/archive.php?author=$1 [L]

Is there anyway I can get rid of:

archive.php?

with an end result of:

https://www.zurimagazine.com/blog/author/zuri-magazine

Drew McLellan

Drew McLellan 2638 points
Perch Support

Remember the order of rewrite rules is important. /blog/author might match a pattern for /blog/some-post-slug so make sure that more-specific rules come first.

Hi Drew,

i've added the author code at the bottom of my file and still no luck

Drew McLellan

Drew McLellan 2638 points
Perch Support

What happens?