views:

22

answers:

2

Hi, I am trying to rewrite url and it fails. May I know what is wrong? can someone please enlighten me? I placed the code in .htaccess. I have enabled rewrite_module too. thanks.

RewriteEngine On
RewriteRule /place/^([a-zA-Z0-9])$ /placelink.php?lid=$1

For example: domain.com/place/xyz -> domain.com/placelink.php?id=xyz

Update:

I have just found out that my syntax is now correct. But it is not mod_rewrite that is not working. can someone please help me? phpinfo shows mod_rewrite module is available. Please help. urgent here. Thanks.

Update 2

RewriteEngine On 
RewriteRule ^/?test\.html$ test.php [L]
A: 

^ means 'the start of the string. /path/ is a literal. So you're asking for a string which has /path/ in it, after which the string starts. This is logically impossible. See http://regularexpressions.info for more information about regexes.

Wrikken
I have taken out both ^ and $. But not working too. I have updated my ques.
benmsia
Hi wrikken, pls read my update. thanks
benmsia
@benmsia: it is perfectly possible you are not allowed to add rewriterules in .htaccess files. What is the AllowOverride directive in Apache set to?
Wrikken
A: 

Chances are you want this...

RewriteEngine On
RewriteRule ^place/([a-zA-Z0-9-]+)/?$ /placelink.php?lid=$1

This will take requests for..

domain.com/place/the-moon

...and will serve up...

domain.com/placelink.php?lid=the-moon
Cags
hi cags, pls read my updates. thanks.
benmsia
@benmsia your update isn't useful, because it doesn't show what you're doing now.
hobbs
@hobbs initially, i thought it is due to syntax error that cannot get the url rewrite. But now i realized that even a simple rewrite also my server could not perform. Even after setting enabling mod_rewrite. May I know how to solve this problem? How to enable it? Is there any steps that I have left with just uncomment the rewrite module in httpd? thanks for your reply and do ask me if my comment is unclear. thanks.
benmsia
@benmsia No. It's more likely that your "simple rewrite" is *also* wrong.
hobbs
@hobbs, the update 2 is my simple rewrite. when i type test.html, it will shows the content of test.php. Is there any mistake? thx..
benmsia
Define 'not working', if you are getting a 500 server error, then yes, mod_rewrite probably isn't enabled, or is failing. If nothing is happening you are probably just expecting the wrong thing to happen. It's extremely common (and infuriating) for people to leave the links in their site as domain.com/placelink.php?lid=the-moon, and expect that rewrite rule to somehow magically change the link in their users address bar, this is the opposite of what mod_rewrite is intended for. The links on your site need to be of the form domain.com/place/the-moon. If this doesn't apply I refer you to point 1
Cags