Friendly URLs in PHP - php

This is the URL path I currently use:
/index.php?pid=211
I want to get the URL path as
/index/211/title of the product
How to do user friendly URLs in PHP?
And how to get the value of the "title"?
Regards,

In you html code you must write like this:
<a href='http://www.domain.com/index/211/title-goes-here'>url_text</a>
and in the htaccess file adapt the following:
Options +SymLinksIfOwnerMatch
RewriteEngine on
RewriteRule ^([a-zA-Z-]+)$ index.php?action=$1 [NC,L]
RewriteRule ^(member)-([0-9-]+)$ index.php?action=member&id=$2 [NC,L]
RewriteRule ^([a-zA-Z-]+)/([a-zA-Z-]+)-([0-9-]+)$ index.php?action=$1&saction=$2&sid=$3 [NC,L]
RewriteRule ^([a-zA-Z-]+)/([0-9-]+)$ index.php?action=$1&id=$2 [NC,L]
RewriteRule ^([0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/(.*).html$ index.php?action=details&id=$1&p1=$2&p2=$3&p3=$4 [NC,L]

Related

.htaccess redirect with Multiple query parameter

I would like to use following URL for my web site.
http://mywebsite.com/product.php
to
http://mywebsite.com/product
http://mywebsite.com/product.php?id=5
to
http://mywebsite.com/product/5
http://mywebsite.com/product.php?action=delete&id=5
to
http://mywebsite.com/product/delete/5
http://mywebsite.com/product.php?action=edit&id=3
to
http://mywebsite.com/product/edit/3
I use this code on my .htaccess file
RewriteEngine on
RewriteRule ^product product.php
RewriteRule ^product/([a-zA-Z0-9_-]+)$ product.php?id=$1
RewriteRule ^product/([a-zA-Z0-9_-]+)/$ product.php?id=$1
But problem is when i use http://mywebsite.com/product/5 and display with GET variable,
it does not pass the id parameter and how can i achieve the multiple query from my url?
Try this htaccess :
RewriteEngine on
RewriteRule ^product/?$ product.php [L]
RewriteRule ^product/([a-zA-Z0-9_-]+)/?$ product.php?id=$1 [L]
RewriteRule ^product/delete/([a-zA-Z0-9_-]+)/?$ product.php?action=delete&id=$1 [NC,L]
RewriteRule ^product/edit/([a-zA-Z0-9_-]+)/?$ product.php?action=edit&id=$1 [NC,L]

how to add pagination in htaccess

hello i am looking to add pagination with htaccess i have htaccess file which rewrite my php urls from mysite.com/category.php?uid=123-slug-name to mysite.com/category/123-slug-name but i want to add pagination like this
> mysite.com/category/123-slub-name/page/1
> mysite.com/category/123-slub-name/page/2
> mysite.com/category/123-slub-name/page/last etc
but i dont know exactly how to do this here is my htaccess file code
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9-/]+)$ category.php?id=$1
RewriteRule ^category/([a-zA-Z0-9-/]+)/$ category.php?id=$1
RewriteRule ^([a-zA-Z0-9-/]+)$ article.php?url=$1
RewriteRule ^([a-zA-Z0-9-/]+)/$ article.php?url=$1
You can use:
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9-/]+)/page/(.+)/?$ category.php?id=$1&page=$2 [NC,L]
RewriteRule ^category/([a-zA-Z0-9-/]+)/?$ category.php?id=$1 [L]
RewriteRule ^([a-zA-Z0-9-/]+)/?$ article.php?url=$1

URL rewrite for sub-folder, sub-folder need beautiful SEO friendly URL

I am working with custom website. My current folder structure like:
Main Dir (httpdocs)/Stores (sub-folder) / eol (sub-folder and site files)
Full Path /httpdocs/stores/eol
and I have three pages Like
categories.php (categories?category_id=352)
allproducts.php (allproducts?cat_id=624)
products.php (products?productid=1118&cat_id=296)
My Current .htaccess is
RewriteEngine On
RewriteBase /stores/eol/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L] # Removing .php extention
RewriteRule ^([^/]*)\.html$ /stores/eol/categories?category_id=$1 [QSA,NC,L]
RewriteRule ^cat-([^/]*)\.html$ /stores/eol/allproducts?cat_id=$1 [QSA,NC,L]
RewriteRule ^([^/]*)/([^/]*)\.html$ /stores/eol/products?productid=$1&cat_id=$2 [QSA,NC,L]
Now want to show page with beautiful or SEO friendly URL.
Your help would be very much appreciated.
Assuming you're aiming for:
352.html -> categories.php?category_id=352
cat-624.html -> allproducts.php?cat_id=624
1118/296.html -> products.php?productid=1118&cat_id=29
I believe you're looking for something like this:
RewriteEngine On
RewriteBase /stores/eol/
RewriteRule ^(\d+)\.html$ categories.php?category_id=$1 [L]
RewriteRule ^cat-(\d+)\.html$ allproducts.php?cat_id=$1 [L]
RewriteRule ^(\d+)/(\d+)\.html$ products.php?productid=$1&cat_id=$2 [L]

get page no from url using htaccess

I want to get page no from url
Eg:
www.example.com/education/tutorial/php-234.html
to
PageNo=234
and
www.example.com/course-1504.html
to
PageNo=1504
I am using the following code in .htaccess
RewriteEngine on
RewriteRule ^([0-9]+).html$ Pages.php?PageNo=$1 [NC,L]
But it is not working
If we use
RewriteRule ([0-9]+).html$ Pages.php?PageNo=$1 [NC,L]
I got page no, But
RewriteRule ^([a-zA-Z0-9-]+).html$ Pages.php?PageName=$1 [NC,L]
is not working
Any suggestion for both combination
try:
RewriteEngine on
RewriteRule ^(.*)-([0-9]+)\.html$ Pages.php?PageName=$1&PageNo=$2 [L,QSA]

.htaccess short and friendly url

I'm looking for the right .htaccess rule to make a Facebook.com/user URL like
What I want if I access for example
www.domain.com/StackOverFlow
It will be rewrite to
www.domain.com/index.php?category=StackOverFlow
Or
www.domain.com/category.php?item=StackOverFlow
Any help? I've tried some question here, but they doesn't explicit do this behavior.
Thanks in advance
Edited:
Forgot to say that I only want to be redirected using this rule, anything that after the domain, doesn't have any extension
For example it should redirect www.domain.com/categoryDescription but no www.domain.com/categoryDescription.php or www.domain.com/categoryDescription.html
The example below takes the URI after .com/ and assigns that to $1.
You can do the same for "item"
RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?category=$1 [L]
<IfModule mod_rewrite.c>
RewriteEngine on
# Rewrite URLs of the form 'x' to the form 'index.php?category=x'.
RewriteRule ^(.*)$ index.php?category=$1 [L,QSA]
</IfModule>
Try:
RewriteRule ^StackOverFlow$ index.php?category=StackOverFlow [NC,L]
or:
RewriteRule ^StackOverFlow$ category.php?item=StackOverFlow [NC,L]
In generally:
RewriteRule ^([^/]*)$ index.php?category=$1 [NC,L]
or:
RewriteRule ^([^/]*)$ category.php?item=$1 [NC,L]

Categories