0

When designing a website what would be good practice for the url designing and related backend. Say I have a website with news posts on it. I would like the url to look like this:

mysite.com/news/newsItem1

Normally an url like this would reference to a folder called newsItem1 on the server. But in this case there will be a lot of newsItems (stored as xml files), and I don't think it's a good idea to create a folder for every item.

The same thing happens when I make the url like this:

mysite.com/news/newsItem1.html

In that case I would have to make a html file for every newsItem.

What I would like is an url that is different for every newsItem, but on the server it basically points to a php file that parses the matching xml file and returns its contents. How would I do that?

1 Answer 1

1

For this you have to use .htacces which allows you to redesign the url.
you can use something like this for that you want :

http://www.mysite.com/news/newsItem.php?id=1

and write the rewrite rule for url design in .htaccess file as:

RewriteEngine On
RewriteRule ^id/([^/]*)\.html$ /news/newsitem.php?id=$1 [L]

and the result will be as:

http://www.mysite.com/id/1.html

Here is the link for .htaccess tutorial http://www.htaccess-guide.com/

Sign up to request clarification or add additional context in comments.

1 Comment

It looks like this is exactly what I was looking for, I will try it and accept your answer if I can get it working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.