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
Related
I am trying to set up my api to have 2 endpoints, and the simplest way I have seen to do this is to have a .htaccess file that would redirect something like www.website.com/api/category/platform to display the same as www.website.com/api/index.php?category=platform . The issue I am now running into is that I want it to include a second parameter such as www.website.com/api/index.php?category=platform&filter=price to be the same as www.website.com/api/category/platform/price or even www.website.com/api/platform/price
The current .htaccess file is
RewriteEngine On
RewriteRule ^/?category/([^/d]+)/?$ index.php?category=$1 [L,QSA]
I figured it out and I was able to use something along the lines of
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ project3/api/index.php?category=$1&filter=$2 [L]
You can use smthing like this.
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?category$ $1category/ [R=301,L]
RewriteRule ^ - [L]
RewriteRule . index.php [L]
i get the $_GET['id'] from url to show a page, to htaccess i have the follow code to show like this shop/123 and not shop.php?id=123
RewriteEngine on
RewriteRule shop/(.*)/ shop.php?id=$1
RewriteRule shop/(.*) shop.php?id=$1
My problem is .. If i add to url shop/123/test/test/test this still working again and i have problems with the share links etc.
How i can fix it to takes only one parametes else to go to 404?
Sorry for my English
You can use this :
RewriteEngine on
RewriteRule ^shop/([^/]+)$ /shop.php?id=$1 [L]
This will rewrite /shop/foobar to /shop.php?id=foobar, but will not rewrite /shop/foobar/ with a traling slash or extra path-info .
If id is only numerical, you can change the rewrite rule to this:
RewriteEngine on
RewriteRule shop/(\d+)/ shop.php?id=$1
RewriteRule shop/(\d+) shop.php?id=$1
If you also have alphabets in id:
RewriteEngine on
RewriteRule shop/([a-zA-Z\d]+)/ shop.php?id=$1
RewriteRule shop/([a-zA-Z\d]+) shop.php?id=$1
Try this:
<IfModule mod_rewrite.c>
RewriteEngine On
</IfModule>
RewriteRule ^shop/([0-9]+)/(.*) shop.php?id=$1 [L]
RewriteRule ^shop/([0-9]+)/(.*)/ shop.php?id=$1 [L]
Hope this will work. Thanks.
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]
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]
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]