call page which use htaccess - php

I have htaccess file and this is in it:
RewriteEngine On
Options +FollowSymlinks
RewriteBase /project/
RewriteRule ^betNow/$ index.php?action=betNow [L]
RewriteRule ^(.*)/betNow/$ index.php?action=betNow [L]
RewriteRule ^(.*)/betNow/([0-9]+)$ index.php?action=betNow&id=$2 [L]
and it works, when I type localhost/project/betNow/
but I can't figure out last rule
I tried with localhost/project/betNow/4
and localhost/project/betNow/id=4
and that's not working. what am I doing wrong?
Thanks in advance

You have defined your RewriteBase /project/ and your site apparently resides in http://localhost/project/ - so when you call http://localhost/project/betNow/ the request string handed over to the rewrite rules is just betNow/.
Therefor your rules starting with ^(.*)/betNow will not match. You just need:
RewriteRule ^betNow/$ index.php?action=betNow [L]
RewriteRule ^betNow/([0-9]+)$ index.php?action=betNow&id=$2 [L]
And you can use
http://localhost/project/betNow/ --> index.php?action=betNow
http://localhost/project/betNow/4 --> index.php?action=betNow&id=4

Shouldn't the rules be
RewriteEngine On
Options +FollowSymlinks
RewriteBase /project/
RewriteRule ^betNow/$ index.php?action=betNow [L]
RewriteRule ^betNow/([0-9]+)$ index.php?action=betNow&id=$2 [L]
You may need to put a / after both of the ^ characters in the rewrite rules too

Instead of localhost/project/betNow/id=4 try: localhost/project/betNow/id/4
And use:
RewriteRule ^(.*)/betNow/id/([0-9]+)$ index.php?action=betNow&id=$2 [L]

Related

redirecting a php url with 2 parameter

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]

Rewrite query into path using htaccess

How can I make htaccess rewrite the following URL structure:
http://example.com/detail.php?id=polo&categ=wears
to
http://example.com/wears/polo/
I have tried the below code but it didn't work for me.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.+)/(admin|css|fonts|ico|include|js|images|img|products|slide)/(.*)$ $2/$3 [L]
RewriteRule ^(.*)/(.*)/$ detail.php?id=$1&categ=$2
</IfModule>
Your code works for me when I include the trailing slash in the URL.
working -> http://example.com/wears/polo/
not working -> http://example.com/wears/polo
Also, you need to exclude the slash character from the .* expression.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.+)/(admin|css|fonts|ico|include|js|images|img|products|slide)/(.*)$ $2/$3 [L]
RewriteRule ^([^/]*)/([^/]*)/?$ detail.php?id=$1&categ=$2
</IfModule>
Try this
RewriteEngine on
RewriteRule ^/(\w+)/(\w+)$ detail.php?categ=$1&id=$2 [NC,L]

Php htaccess RewriteRule how to fix

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.

.htaccess code help in admin folder rewrite

i done url rewrite below in .htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^admin/(.*) Rrrrr/core-.php [L]
RewriteRule (.*) Rrrrr/core.php [L]
All the files in admin folder should rewrite into core-.php
And all other files should rewrite into core.php
But all the files are rewriting into the core.php only.
http://www.konasignature.com/shop/women/dresses - this url working as per second command rule
But http://www.konasignature.com/admin/ - not working. 404 page only
This code works for me !
RewriteEngine on
RewriteRule ^admin/(.*) login/core-$1 [L]
Please use $ for this command
RewriteEngine On
RewriteBase /
RewriteRule ^admin/(.*)$ Rrrrr/core-.php [L]
RewriteRule (.*) Rrrrr/core.php [L]

.htaccess url rewriting

I need a rewrite rule to rewrite the following:
www.abc.com/page/xyz to www.abc.com/xyz
remove **"page"** from url
I think it's more like this:
RewriteBase /
RewriteRule ^(.*)$ page/$1 [L]
If I understand what you're trying to do.
Like so:
RewriteBase /
RewriteRule ^page(/.*)?$ $1 [L]
If you only want to redirect page/xyz then you can use:
RewriteEngine on
RewriteRule ^/page/xyz$ /xyz [L]
If you want to redirect anything within the page directory, then use:
RewriteEngine on
RewriteRule ^/page(/.*$)$ $1 [L]

Categories