Reformulating URL in htacess

Asked

Viewed 79 times

0

I am trying to rephrase the url that causes you to change the page. I have the following URL

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

The way above quotes the pagination works perfectly. But that improve the url with htacess. I would like it to be like this:

www.site.com/Humor/3

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

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

1 answer

2


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

Example with 1 querystring

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

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

Explanation:

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

Example with 2 querystring (Ex.: 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/en/products

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


Example with 2 querystring (E.g.: page + sub-page)

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.