Home » Php » php – user manual (seo + auto generate)

php – user manual (seo + auto generate)

Posted by: admin July 12, 2020 Leave a comment


i have a website that allows people to get the manual online. i have a new version of the manual where everything is generated dynamically using php and mysql. so no more html generated.

i have the manual in french and english now. i learn that for search engine purposes it will be good if i have url that are friendly with gogole and yahoo etc…

now here’s my problem:

i want to show the url like this:

  • /manual/ that will go to the main manual page where the user choose a lang
  • /manual/fr/ this will display the list of all available chapters
  • /manual/fr/1.0 this will display the chapter 1

i got the idea where i need to use something like :

rewriterule /manual/(.*)/(.*)/(.*)/ index.php?lang=$1& ...

can i do this using 1 rule? or i need multiples?

thanks so much

How to&Answers:

Here’s what you have to do:

RewriteEngine On
RewriteRule ^manual/?$ index.php?action=selectLang [L,NC,QSA]
RewriteRule ^manual/(fr|en)/?$ index.php?action=listChapter&lang=$1 [L,NC,QSA]
RewriteRule ^manual/(fr|en)/([0-9\.]+)(/[^/]+)?/?$ index.php?action=listChapter&lang=$1&chapter=$2 [L,NC,QSA]

The first one will load the page where the user choose a lang. In your PHP you can check the $_GET['action'] so you can load the “select the lang” page. The second same idea as the first one but for the chapter list. Now the third one, you can either use /manual/fr/1.0 or /manual/fr/1.0/chapter-title. This will work better for SEO if you add the title.

[] at the end of each RewriteRule are the flag, learn more here: http://httpd.apache.org/docs/2.3/rewrite/flags.html