0

I have a website built in PHP. Currently my URLs look like:

http://www.domain.com/web/views/site/event.php?id=1&name=Test

I want them to be like:

http://www.domain.com/event/id/1/name/Test

How can I achieve this? I have tried multiple tutorials and have checked for answers in stackoverflow but have not been able to find a proper solution.

Any thoughts?

Thanks in advance.

Kvnamo
  • 157
  • 1
  • 2
  • 9
  • 2
    Possible duplicate of [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](http://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – Croises Nov 29 '16 at 00:36
  • Make your link `http://www.domain.com/event/id/1/name/Test` then have a rewrite rule that serves `http://www.domain.com/event/id/1/name/Test` as `http://www.domain.com/web/views/site/event.php?id=1&name=Test`. Then capture the values after `id` and `name`. – chris85 Nov 29 '16 at 00:44

1 Answers1

0

Create an .htaccess file and add the following lines:

RewriteEngine On    # Turn on the rewriting engine
RewriteBase /
RewriteRule    ^event/id/([A-Za-z0-9-_]+)/name/([A-Za-z0-9-_]+)/?$ web/views/site/event.php?id=$1&name=$2    [NC,L]

Two things that you should keep in mind:

  1. .htaccess should be located at your root directory

  2. Make sure that apache has the following directive regarding your root directory:

    AllowOverride All

This is how is done:

If you have root access to your server, edit the httpd.conf file, find the root <Directory> line, and change it to this:

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

If you don't have root access, ask your server administrator to do that for you.

Theo Orphanos
  • 1,255
  • 16
  • 25