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.
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 have a .htaccess which reads as follows
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^([a-z0-9\-]+) /index.php?page_name=$1 [L]
I want the link
http://www.solublesilicates.com/our-services when clicked should read as http://www.solublesilicates.com/?page_name=our-services.
Please do help.
RewriteRule ^([a-z0-9\-]+)$ /index.php?page_name=$1 [L, QSA]
Just change it to the above. Should work perfectly.
You have error in your syntax. Your regex should end with $ sign
RewriteRule ^([a-z0-9\-]+)$ /index.php?page_name=$1 [L]
Change the Rewrite Rule to
RewriteRule ^([A-Za-z0-9\-]+) index.php?page_name=$1 [L,QSA]
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]
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]
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]