logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

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.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: htaccess mod_rewrite - friendly URLs
Author
stanhowe



Joined: 18 Aug 2017
Posts: 2
Location: United Kingdom

PostPosted: Fri 18 Aug '17 21:19    Post subject: htaccess mod_rewrite - friendly URLs Reply with quote

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 Smile


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

PostPosted: Mon 21 Aug '17 0:30    Post subject: Reply with quote

Hi Stan,

Try with this:

RewriteRule ^ecommerce/(.*)$ /ecommerce/product?id=$1 [L]

Regards Smile
Back to top
stanhowe



Joined: 18 Aug 2017
Posts: 2
Location: United Kingdom

PostPosted: Fri 25 Aug '17 22:18    Post subject: Reply with quote

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


Reply to topic   Topic: htaccess mod_rewrite - friendly URLs View previous topic :: View next topic
Post new topic   Forum Index -> Apache