Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn dynamic URL into static URL

I am developing a website using PHP and Apache. I wanna turn my URLs from

www.example.com/book.php?book=title

into something like this, if it is possible of course:

www.example.com/book/title

Notice that the title of the books are unique and cannot be repeated.

I`ve read about this, but none of the posts were clear enough for a beginner like me. Do you guys know any tutorial that explains that?

Thanks.

like image 955
rlc Avatar asked Apr 22 '10 15:04

rlc


People also ask

How we can convert dynamic URL into static URL?

Here you will know how to change dynamic URL to static URL with the help of the . htaccess file. . htaccess will provide the features of URL rewriting. If the requirement for you to rewrite the URL (dynamic URL to static URL) is limited, then the rules described in the examples of Rodolphe in a hardcode .

Why are dynamic URLs bad for SEO?

Dynamic URLs have the disadvantage that different URLs can have the same content. So different users might link to URLs with different parameters which have the same content. That's one reason why webmasters sometimes want to rewrite their URLs to static ones.

Is a URL static or dynamic?

URLs are classified into two types: static and dynamic. A static URL is one in which the content of the web page remains the same as long as the changes are not hard coded within the HTML. On the other hand, a dynamic URL is one which is a result of a search within a website driven by a database running on some script.

Is Google static or dynamic?

Even though Google is a dynamic website, it encourages site owners to use static parts such as Accelerated Mobile Pages (AMP). Even though Google is a dynamic website, it may have certain static parts.


1 Answers

Here's the way kohana (and 99.99% of php frameworks) does it

Add an .htaccess file(if using apache)

# Turn on URL rewriting
RewriteEngine On

RewriteBase /

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]

This redirects all urls to index.php. index.php will be some sort of front controller that loads scripts based on the url

So in your example:

localhost/book/title

index.php would be loaded. It would go into the url and get the page (controller) to load that will actually do all the work. in this case maybe books.php. books.php would get the title of the book from the url and then search a database or do whatever it has to with that name.

like image 92
Galen Avatar answered Oct 06 '22 00:10

Galen