Brad Hazelnut
Brad Hazelnut

Reputation: 1621

Rewrite numbers to default page

I am trying to rewrite a condition that can take any page that has numbers.html, lets say the like the following:

12345.html
33443.html
234545656.html
9797423.html

and just redirect it to index.php

RewriteRule ^([0-9]+)$ index.php [L]

I tried the following but it doesn't work, any help is very much appreciated.

Upvotes: 0

Views: 18

Answers (1)

arkascha
arkascha

Reputation: 42885

Two immediate issues with your code:

  1. you have to switch on the rewriting engine prior to using it and
  2. if you want to match file names ending with .html, then you have to code that.

Have a try with this:

RewriteEngine on
RewriteRule ^([0-9]+)\.html$ index.php [L]

Then a few more hints:

  • the code you tried will only work in .htaccess style files. But the usage of such files has to be enabled first in your http server configuration.
  • a .htaccess style file has to be placed at the correct location, in this example within the folder actually holding the index.php file.
  • the rewriting module has to be installed and enabled, without those commands will not be available.

And a general remark:

Those .htaccess style files are notoriously error prone, hard to debug and they really slow down the http server, often for nothing. You should always prefer to place such commands inside the real host configuration of your http server. .htaccess style files are only offered as a last option for situations where you have no access to that configuration, for example when using a really cheap shared hosting provider.

Upvotes: 2

Related Questions