开发者

Hiding URL parameters with .htaccess while still making them available to $_GET

I have a script on my site ('write-review.php') that takes an optional url parameter 'site'. So server-side requests could be:

/reviews/write-review.php

or

/reviews/write-review.php?site=foo

I'm using .htaccess to create search engine friendly URLs and hide my php extensions, so that requests to this script are respectively rewritten as

/reviews/write-a-review/

or

/reviews/write-a-review/foo

I think having 'foo' in the URL may cause confusion for my users, so I'm trying to write an htaccess rewrite rule that removes 'foo' while still passing this variable to my script. Thus, a request to /reviews/write-a-review/foo would be rewritten as /reviews/write-a-review/ but write-review.php would be passed 'foo'.

Th开发者_运维百科e rewrite rule I currently have in place is:

RewriteRule ^reviews/write-a-review/?$ reviews/write-review.php
RewriteRule ^reviews/write-a-review/([a-zA-Z0-9_-]+)/?$ reviews/write-review.php?site=$1

Is it even possible to do what I've described above? There are MANY questions on Stack Overflow that are similar to this, and I've read through at least a dozen, but I haven't found a way to do this specifically.

Any help is really appreciated.

Thanks,

Chris


Is it even possible to do what I've described above?

No. To alter the actual URL the user inputs, you'd have to do a header redirect, during which you would lose foo.

This is not possible, except maybe by using ridiculous technical tricks like storing foo in a session variable or something. I would not recommend going that route.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜