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]
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]
Having a bit of a problem and wondering what I've done wrong.
Options -Multiviews
RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.rentus.com/$1 [R=301,L]
RewriteRule ^([a-z]+)\/?$ $1.php [NC]
RewriteRule ^([-a-z]+)\/([-a-z]+)/?$ category.php?param=$1¶m2=$2 [L,QSA]
RewriteRule ^([-a-z]+)\/([-a-z]+)/?$ city.php?param=$1¶m2=$2 [L,QSA]
So it works with general pages like "/about/" and then category.php with query strings on category.php "/category/hats/".
When I try to load "/city/losangeles/" Its loading category.php file instead of city.php file. Any idea what I can do to make this work properly and use the php file I tell it too?
Your rules are the exact same, so it wont ever reach the second:
RewriteRule ^([-a-z]+)\/([-a-z]+)/?$ category.php?param=$1¶m2=$2 [L,QSA]
RewriteRule ^([-a-z]+)\/([-a-z]+)/?$ city.php?param=$1¶m2=$2 [L,QSA]
Try this (Be aware, your param will no longer contain category/city, and will now include the actual category or city):
RewriteRule ^category\/([-a-z]+)/?$ category.php?param=$1 [L,QSA]
RewriteRule ^city\/([-a-z]+)/?$ city.php?param=$1 [L,QSA]
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
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]
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]