7 Replies - 3051 Views - Last Post: 07 April 2014 - 12:08 PM

#1 Keylogger  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 344
  • Joined: 14-February 11

.htaccess rewrite rule for several parameters

Posted 04 April 2014 - 10:36 AM

Hi guys,

I'm trying to write a rule for several parameters but I can't even make this work for only one parameter. :gun_bandana:/>

Current url:
http://localhost/noyk/clients/clients.php?name=dreamincode
http://localhost/noyk/clients/clients.php?name=dreamincode&category=technology

Final url:
http://localhost/noyk/clients/dreamincode
http://localhost/noyk/clients/dreamincode/technology 

I'm using XAMPP and I have this line enabled.
LoadModule rewrite_module modules/mod_rewrite.so

Then, in my htacces, which is in my root folder:
RewriteEngine On
RewriteRule ^([^/]*)$ /noyk/clients/index.php?name=$1 [L]
RewriteRule ^([^/]*)$ /noyk/clients/index.php?name=$1&category=$2 [L]


None of this works. When I type in the url
http://localhost/noyk/clients/dreamincode
http://localhost/noyk/clients/dreamincode/tecnology

I receive the following error:

Quote

The requested URL /noyk/clients/dreamincode was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


Is This A Good Question/Topic? 0
  • +

Replies To: .htaccess rewrite rule for several parameters

#2 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 486
  • View blog
  • Posts: 1,807
  • Joined: 15-January 14

Re: .htaccess rewrite rule for several parameters

Posted 04 April 2014 - 11:33 AM

I've moved this from the PHP forum to the Web Servers forum.
Was This Post Helpful? 0
  • +
  • -

#3 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5388
  • View blog
  • Posts: 27,383
  • Joined: 10-May 07

Re: .htaccess rewrite rule for several parameters

Posted 04 April 2014 - 11:44 AM

What you are trying to do is called clean urls :

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ clients.php?name=$1
RewriteRule ^([a-zA-Z0-9]+)/$ clients.php?name=$1



Since your directories do not change, I don't believe you need to target anything more than changing the php file & the argument to the new /item/.
Was This Post Helpful? -1
  • +
  • -

#4 Keylogger  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 344
  • Joined: 14-February 11

Re: .htaccess rewrite rule for several parameters

Posted 07 April 2014 - 01:20 AM

View Postno2pencil, on 04 April 2014 - 11:44 AM, said:

What you are trying to do is called clean urls :

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ clients.php?name=$1
RewriteRule ^([a-zA-Z0-9]+)/$ clients.php?name=$1



Since your directories do not change, I don't believe you need to target anything more than changing the php file & the argument to the new /item/.

Worked thanks. However, instead of put "+1 this post was usefull" I clicked the red button..and I can't figure out how do I change??
Was This Post Helpful? 0
  • +
  • -

#5 Keylogger  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 344
  • Joined: 14-February 11

Re: .htaccess rewrite rule for several parameters

Posted 07 April 2014 - 01:34 AM

Hey, sorry again but actually it's not working.
RewriteEngine On

RewriteRule ^([a-zA-Z0-9]+)$ clients.php?name=$1
RewriteRule ^([a-zA-Z0-9]+)/$ clients.php?name=$1


Shouldn't be ?:
RewriteRule ^([a-zA-Z0-9]+)$ index.php?name=$1
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?name=$1

Even if so, I have put this .htaccess file inside the folder clients and it's not working.

Edit: Solved this way http://forum.codecal...-urls-with-php/

This post has been edited by Keylogger: 07 April 2014 - 01:42 AM

Was This Post Helpful? 1
  • +
  • -

#6 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5388
  • View blog
  • Posts: 27,383
  • Joined: 10-May 07

Re: .htaccess rewrite rule for several parameters

Posted 07 April 2014 - 11:40 AM

Thank you for sharing your overall solution!
Was This Post Helpful? 1
  • +
  • -

#7 Keylogger  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 344
  • Joined: 14-February 11

Re: .htaccess rewrite rule for several parameters

Posted 07 April 2014 - 11:52 AM

View Postno2pencil, on 07 April 2014 - 11:40 AM, said:

Thank you for sharing your overall solution!

I can not change your reputation? It was a misclick..it should allow to change..
Thanks anyway.
Was This Post Helpful? 0
  • +
  • -

#8 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5388
  • View blog
  • Posts: 27,383
  • Joined: 10-May 07

Re: .htaccess rewrite rule for several parameters

Posted 07 April 2014 - 12:08 PM

No worries :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1