Sign up ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have a php template which has one index.php and all the different pages (content1.html, content2.html, etc) are shown on the index.phppage. So for example I can open and it will show the content1.html.

Now what I would like is this: often you see websites where the URL is like: I know how to do this with an exclamation mark like where you just don't write the index.php.

But how can I make a URL name, which is completely different from the filename? For example, would show me the content of index.php?content1

share|improve this question

migrated from Jun 29 '11 at 18:12

This question came from our site for professional and enthusiast programmers.

3 Answers 3

You probably should look into mod_rewrite which could help you out.

See this cheat sheet for some help.

share|improve this answer
ok thanks to you 2, this would work for static pages. But what about page names which are dynamically created and stored in a mysql database. Say for example I create a new page index.php?newpage and I save the url name of the page in a database. Now the htaccess would have to connect to the database to get the url name wouldnt it? Btw stackoverflow is doing exactly what I want to achieve, look at the url… – phpheini Jun 29 '11 at 17:54

.htaccess is definitely one route you could go for rewriting URL's. But, I think that the piece you're missing is the part where you should store your page's content in a database or store the file names and URL slugs of the pages in an array on index.php to pull from. This way you can have a different URL slug than the actual file name.

For instance, if you use a rewrite rule in .htaccess that says all requests for the URL need to display the content from content1.html, you will need to specify somewhere that 'the-page-you-want' refers to content1.html.

share|improve this answer

refer to @Pål Brattberg's answer for detailed description

@phpheini You don't need to bind the .htaccess file to the database, suppose if you want the URL for your article like

RewriteEngine On
RewriteBase /
RewriteRule ^([a-z]+)/([0-9]+)/(.*?).html$ /index.php?type=$1&article_id=$2

Here $1 and $2 get the article type and article_id which can change. index.php can output content based on the parameters.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.