views:

27

answers:

1

Hello,

I have a hyperlink that looks like this:

http://domain.com/sample/comments/65

And when I click on it, it goes to this:

http://domain.com/sample/comments/index.php?submissionid=65

I'm using a rewrite rule to make it do this. This is what I want, except I also want the URL displayed in the browser to still look like "http://domain.com/sample/comments/65."

How can I do this? The .htaccess file is displayed below.

RewriteEngine on
RewriteRule ^comments/([0-9]+)?$ http://domain.com/sample/comments/index.php?submissionid=$1 [NC,L]

Thanks in advance,

John

A: 

You must remove the part http://domain.com/sample/, otherwise it will force a redirect:

RewriteEngine on
RewriteRule ^comments/([0-9]+)?$ comments/index.php?submissionid=$1 [NC,L,B]

The B flag is also necessary because you're using the backreference inside a query string, which requires escaping.

The manual says (emphasis mine):

When using the rewrite engine in .htaccess files the per-directory prefix (which always is the same for a specific directory) is automatically removed for the pattern matching and automatically added after the substitution has been done. This feature is essential for many sorts of rewriting; without this, you would always have to match the parent directory, which is not always possible. There is one exception: If a substitution string starts with http://, then the directory prefix will not be added, and an external redirect (or proxy throughput, if using flag P) is forced. See the RewriteBase directive for more information.

This would not be case if you put the rewrite rule in the virtual host or main configuration as long the request host and the host in the rewrite rule matched.

Artefacto