I like php
I like php

Reputation: 29

.htaccess mod_rewrite, probably very simple

I am trying to take my link domain.com/view.php?id=12345 and my it to be domain.com/view/12345

I'm unsure on to have I need to do, or what so here are my questions:

  1. Do I need to make a view folder and put a file in there?
  2. How would I make the rewrite rule?
  3. How can I make it redirect to the new link?
  4. What would I link my pages as?

Here is my current rewrite rule. I know it's using the file because I did a test earlier from anther questions I found.

RewriteEngine On
RewriteRule ^view/([0-9]+)/$ view.php?id=$1

Upvotes: 0

Views: 43

Answers (1)

Peter Porfy
Peter Porfy

Reputation: 9040

  1. You don't need a folder.

  2. It's ok.

  3. In view.php somewhere:


$filteredId = someFilterFunction($_GET['id']);
header('Location: /view/' + $filteredId);

But it's probably going to be an infinite redirect :) so don't do it. You should check the request url for example.

4 . I don't understand the question.

Upvotes: 1

Related Questions