I would like to know if there is a way to change the url of a .html
file without changing the name of the file. Eg. if I have a website with a page called 1.html
, is there a way to make it appear as mypagename.html
to visitors and crawlers?
Asked
Active
Viewed 2,350 times
1

Steven
- 137
- 2
- 13
-
1I think you can tell Apache eg to serve files under particular URLs. Don't know enough about it to write a proper answer though ;) – Nicolas78 Dec 29 '11 at 00:05
4 Answers
7
This is called URL-rewriting. URL-rewriting implementation differs between different platforms. So, you have to state your server application (e.g. Apache, IIS etc.).

Osman Turan
- 1,361
- 9
- 12
-
Thanks for the responses. Now I know that it would work with eg "RewriteRule ^mypagename.html$ 1.html". One question still though. I plan to do this with a lot of pages. Do you think there is a maximum of pages for this kind of rewriting or doesn't it use too much server resources? Eg. 1.000.000 rewrites or more. Thanks again. – Steven Dec 29 '11 at 01:21
-
You can use regular expression to translate input with a pattern. Actually you're using it even in your example. ^page.html$ is a valid regular expression. You can use something like ^page/(\d+)-(\w+).html$ and you can translate that into "156/hotnews.html" into "page156.html" with that regular expression (e.g. page$1.html rewrite rule). Please a have look at regular expression for more details. – Osman Turan Dec 29 '11 at 07:56
2
If you're running on *nix, it may be easiest to just use a link (soft may require a configuration change, hard will require you to remember that both names refer to the same file).
Note on enabling soft links: https://serverfault.com/questions/244592/followsymlinks-on-apache-why-is-it-a-security-risk
1
You could use the HTML5 History API to push a new, possibly fake, address. I wouldn't suggest it tough.

balupton
- 47,113
- 32
- 131
- 182

Fabián Heredia Montiel
- 1,687
- 1
- 16
- 30
0
Yes there is, but your host must provide URL rewriting. If you're on a Apache server look for .htaccess
capabilities and mod_rewrite
's RewriteRule
directive

ZJR
- 9,308
- 5
- 31
- 38
-
I've removed Linux from your answer, mod_rewrite plays fine (and it's the same) on every platform. – yannis Dec 29 '11 at 07:07
-
Oh well, let's also **[remove Apache](http://stackoverflow.com/questions/60857/mod-rewrite-equivalent-for-iis-7-0)**, as a requirement, then, won't we? :) – ZJR Dec 30 '11 at 04:48