the-catalin
the-catalin

Reputation: 1308

Rewriterule for any URL ending in specific format

I would like to redirect all URLs ending in

data.html to templates/data.php

info.html to templates/info.php

any_other_file.html to templates/index.php

Again, all URLs ending with those names (could be http://some-domain.com/some/long/path/data.html)

Upvotes: 0

Views: 2496

Answers (1)

Mike Rockétt
Mike Rockétt

Reputation: 9007

You can use this in your /.htaccess file:

RewriteEngine On

# Internally rewrite data/info.html to the applicable PHP file
# in the templates directory
RewriteRule (data|info).html$ /templates/$1.php [NC,L]

# Rewrite everything else ending in .html to /templates/index.php
RewriteRule ^(.*).html$ /templates/index.php [NC,L]

Upvotes: 2

Related Questions