-1

I am trying to use a .htaccess file to change my URLs from

xxx/table/change.php?id=1

to

xxx/table/change/1

I have the following code in my .htaccess file, which is in the root folder of my web site.

RewriteEngine On
RewriteRule ^change/([^/\.]+)/?$ change.php?id=$1 [L]
RewriteRule ^change/([^/\.]+)/?$ change.php?id=$1 [L]

However when I restart Apache and visit the desired URL, it still shows up as

xxx/table/change.php?id=1

Any suggestions?

mod_rewrite is uncommented in the httpd.conf file.

Amaerth
  • 178
  • 2
  • 13
  • are you confusing the slashes? supposed to be forward slash `xxx/table/change/1` – Ibu Jul 19 '12 at 18:29
  • Yes, should be forward slash! My mistake. – Amaerth Jul 19 '12 at 18:29
  • 1
    What is `the desired URL` that you're visiting? If you're going to `change.php?id=1` it's not going to redirect you to the clean one. – Steve Robbins Jul 19 '12 at 18:32
  • Yes, your problem seems to be solved. You can visit the page at `xxx/table/change.php?id=1` and `xxx/table/change/1`. Look at Wikipedia, you can use `/w/index.php?title=Wikipedia` or `/wiki/Wikipedia`. Visiting the long URL does nothing with the .HTAccess. Visiting the shortened one does. Therefore, you can use either. – Cole Tobin Jul 19 '12 at 18:34
  • @stevether maybe I am confused as to how this works then. I am looking to click an ID on a table, which links to change.php?id=1, however I am looking for it to redirect to change/1 – Amaerth Jul 19 '12 at 18:34
  • @Amaerth that would require some 301 redirects. – Cole Tobin Jul 19 '12 at 18:34
  • Change the href to the clean url – Steve Robbins Jul 19 '12 at 18:36

1 Answers1

1

how about you use

change/(\d+)$ change.php?id=$1 [L]

that is when you visit

xxx/table/change/1

you are not redirected or 404, you get the correct page. is that what you are looking for?

Ibu
  • 42,752
  • 13
  • 76
  • 103