Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: htaccess mod_rewrite - friendly URLs |
|
Author |
|
stanhowe
Joined: 18 Aug 2017 Posts: 2 Location: United Kingdom
|
Posted: Fri 18 Aug '17 21:19 Post subject: htaccess mod_rewrite - friendly URLs |
|
|
Evening guys,
I have been attempting to get mod rewrite working for product id's but I am having no luck at all. I have tried searching Stack Overflow but there are no clear explanations and I have read the apache documentation.
I have an ecommerce store
http://www.peakwebdesigns.co.uk/ecommerce/store
I want to change these URLs
http://www.peakwebdesigns.co.uk/ecommerce/product?id=3
To:
http://www.peakwebdesigns.co.uk/ecommerce/product/3
I wish to keep /ecommerce/ in the URL
This is my current htaccess rewrite rules:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
RewriteRule ^ecommerce/(.*)$ ecommerce/product?id=$1 [L]
This file has been added to www.peakwebdesigns.co.uk
Other details:
Running Apache 2.4 on my GoDaddy server.
Windows 10 on my PC
Would appreciate any help.
Thanks.
Stan. |
|
Back to top |
|
yosoyminero
Joined: 16 Jun 2015 Posts: 11 Location: Spain
|
Posted: Mon 21 Aug '17 0:30 Post subject: |
|
|
Hi Stan,
Try with this:
RewriteRule ^ecommerce/(.*)$ /ecommerce/product?id=$1 [L]
Regards |
|
Back to top |
|
stanhowe
Joined: 18 Aug 2017 Posts: 2 Location: United Kingdom
|
Posted: Fri 25 Aug '17 22:18 Post subject: |
|
|
Thank you for your reply yosoyminero.
I have tried with the code you provided but it still doesnt work.
I am typing http://www.peakwebdesigns.co.uk/ecommerce/2
but I get a 404 page.
EDIT:
I used the following to get this working:
#Products
RewriteRule ^ecommerce/product/(.*)$ ./ecommerce/product?id=$1 [L,NC]
#Categories
RewriteRule ^ecommerce/category/(.*)$ ./ecommerce/category_page?category_name=$1 [L,NC] |
|
Back to top |
|
|
|
|
|
|