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]
Related
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 redirection is working perfectly in my localhost wampserver. But when uploaded to server(to my site) names with rewrite rule contains "-" is not working.
For example - below code is working:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^supportus/{0,1}$ supportus.php [QSA,L]
</IfModule>
But this isn't working:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^arts-exhibitions/{0,1}$ arts.php [QSA,L]
</IfModule>
For some reason it needed "/" and only $. The below code is working perfectly.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^art-exhibitions$ /arts.php [QSA,L]
</IfModule>
I want the url:
www.tricore.in/viewdoc.php?did=2&title=mca-sem-2-syllabus
to rewrite like:
http://tricore.in/docs/2/mca-sem-2-syllabus
But whenever I am clicking on any Link from www.tricore.in, the rewriting is not happening.
Below is the code of .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^browse/docs/(.*)/(.*)/(.*)/(.*) docs.php?sortby=$1&filter=$2&page=$3&title=$4
RewriteRule ^browse/categories/doc/(.*)/(.*)/(.*)/(.*) categorydocs.php?sortby=$1&filter=$2&page=$3&title=$4
RewriteRule ^browse/categories/docs/(.*)/(.*)/(.*)/(.*) categorydocs.php?sortby=$1&filter=$2&page=$3&title=$4
RewriteRule ^docs/(.*)/(.*) viewdoc.php?did=$1&title=$2
RewriteRule ^confirmemail/(.*) confirmemail.php?code=$1
RewriteRule ^download/doc/(.*)/(.*) downloaddoc.php?DID=$1&title=$2
RewriteRule ^browse/members/(.*)/(.*)/(.*)/(.*) members.php?sortby=$1&filter=$2&page=$3&title=$4
RewriteRule ^categories/ categories.php
RewriteRule ^members/profile/(.*)/(.*) memberprofile.php?pid=$1&username=$2
RewriteRule ^search/(.*)/(.*)/(.*)/(.*) search.php?searchfor=$1&sortby=$2&page=$3&searchterm=$4
RewriteRule ^syndicate/docs/(.*)/(.*) syndicatedocs.php?filter=$1&title=$2
RewriteRule ^resetpassword/(.*) resetpassword.php?code=$1
RewriteRule ^resendconfirmation/(.*) resendconfirmation.php?userid=$1
</IfModule>
<IfModule mod_security.c>
# Turn off mod_security filtering.
SecFilterEngine Off
# The below probably isn't needed,
# but better safe than sorry.
SecFilterScanPOST Off
</IfModule>
Please tell me, where am I going wrong?
Thank you.
Please use the below rewrite rule. For this specific part.
RewriteRule ^docs/([^/]*)/([^/]*)$ /viewdoc.php?did=$1&title=$2 [L]
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]
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]