Jbridgiee
Jbridgiee

Reputation: 59

.htaccess mod-rewrite regex expression

I am making a .htaccess file with various mod_rewrite rules. At the moment, one of my rules is

RewriteRule ^blog /directorypath/index.php [L]

but when you type in http://www.example.com/blogfjdkkfnfdjn, it still loads the blog page.

Basically, I am looking for the regex for it to load the blog when JUST `/blog` is typed in and nothing else

Upvotes: 0

Views: 82

Answers (4)

Book Of Zeus
Book Of Zeus

Reputation: 49867

You can use:

Redirect permanent /blog /directorypath/index.php

If you need a temporary you can use: 302 instead of permanent

OR

RewriteRule ^blog/?$ /directorypath/index.php [R=301,L]

If you need a temporary you can use: R=302

Upvotes: 1

Ulrich Palha
Ulrich Palha

Reputation: 9509

If you access your blog via /blog or /blog/ then I would use

RewriteRule ^blog/?$ /directorypath/index.php [L]

Upvotes: 0

Simone
Simone

Reputation: 21262

RewriteRule ^blog$ /directorypath/index.php [L]

Upvotes: 0

Fad
Fad

Reputation: 9858

Add the $ character to the expression

RewriteRule ^blog$ /directorypath/index.php [L]

Upvotes: 0

Related Questions