TMH
TMH

Reputation: 6246

Make a htaccess rule change the url

Sorry if this has already been asked here, but I haven't found it through looking yet.

I've been asked to remove the /page on our site, and just make it go to the homepage instead. This is easy enough to do in PHP, but I'd rather use my .htaccess file if I can (to learn it better mostly).

In PHP I'd do (some psuedo code)

if($urlIsSlashPage){
    header('Location: /');
    die();
}

Is something like that possible to port to my .htaccess file?

I did have this,

RewriteRule     ^page/$     /   [NC,L] 

And whilst that did show the home page, the URL in the address bar stayed as /page, I want that to display just / instead.

Upvotes: 0

Views: 26

Answers (1)

iovis
iovis

Reputation: 223

You can try with a redirect.

RewriteRule     ^page/?$     http://www.domain.com/   [NC,L,R=301]

Upvotes: 1

Related Questions