47
To access a particular area of the site, I have to indicate one to three parameters in the URL:
Normal URL:
# aceder a um módulo
http://www.meusite.com/index.php?mod=john
# aceder a um sub-módulo:
http://www.meusite.com/index.php?mod=john&call=doe
# Aceder a um conteúdo específico no sub-módulo:
http://www.meusite.com/index.php?mod=john&call=doe&id=1
Through htaccess, I am trying to allow access to modules, sub-modules and specific content as follows:
# aceder a um módulo
http://www.meusite.com/john
# aceder a um sub-módulo:
http://www.meusite.com/john/doe
# aceder a um conteúdo específico no sub-módulo:
http://www.meusite.com/john/doe/1
So far I have the following:
The code below allows me to access the module, but I have to repeat it for each existing module, still missing dealing with sub-modules and specific contents:
# Rewrite the url
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $0 ^john/
RewriteRule ^([^/]*)/([^/]*)$ /index.php?mod=john [NC,L]
RewriteCond $0 ^jane/
RewriteRule ^([^/]*)/([^/]*)$ /index.php?mod=jane [NC,L]
</IfModule>
Question
How do I get through .htaccess
read the addresses so that they can be used in both ways shown above taking into account the three possible parameters?
In this new method, it will also be possible to deal with the part of the however specific as the example:
http://www.meusite.com/john/doe/1
– Zuul
Yes @Zuul, just by modifying the Rewritecond %{REQUEST_URI} /([ /]+)/([ /]+) line to catch such a pattern.
– hernandev
Still, the first method is more secure, even though the code that treats REQUST_URI is a bit confusing
– hernandev