Reformulating URL in htacess

0

I'm trying to reshape the url that causes me to change the page. I have the following URL

www.site.com/categoria.php?cat=Humor&page=3

In the above quote the pagination works perfectly. But what about improving the url with the htacess. I would like it to look like this:

www.site.com/Humor/3

As part of www.site.com/Humor/ already done, I just have no idea how to make paging work.

In my htacess configuration is like this RewriteRule ^(.*)/$ categoria.php?cat=$1

    
asked by anonymous 29.12.2014 / 23:33

1 answer

2

I'll write some examples to see if I can help you ...

Example with 1 querystring

In the case of the URL www.domain.com/pagina-x , it will be interpreted as www.domain.com/index_.php?pagename=pagina-x / p>

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index_.php?pagename=$1

Explanation:

  • RewriteEngine On - > Enable rewriting support
  • RewriteCond %{SCRIPT_FILENAME} !-f - > Does not apply condition to files
  • RewriteCond %{SCRIPT_FILENAME} !-d - > Does not apply condition to directories
  • RewriteRule ^(.*)$ index_.php?pagename=$1 - > Rewrite rule where any string (. *) After the folder, where the .htaccess is, will be interpreted by index.php passed in the variable pagename

Example with 2 querystring (eg language + page)

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)/(.*)$ site.php?lang=$1&pagename=$2

Link user request - > www.domain.com/products

Server-side - > www.domain.com/site.php?lang=en&pagename=products

Example with 2 querystring (eg page + subpage)

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)/(.*)$ index.php?page=$1&subpage=$2

Link user request - > www.domain.com/page_X/subpage_Y

Server-side - > www.domain.com/index.php?page=page_X&subpage=subpage_Y

    
30.12.2014 / 12:46