Jump to content

xampp and mod_rewrite


exhaler

Recommended Posts

Hi,

i just starting to use mod_rewrite on a website, and having a hell of a time to get to work.

using xampp, i checked that the mod_rewrite is enabled in the phpinfo() and replaced AllowOverride None to AllowOverride All in the httpd.conf.

 

placed .htaccess file in the directory with the following code:

Options +FollowSymLinks
RewriteEngine on
RewriteRule event_info/id/(.*)/ event_info.php?id=$1

 

what i want to do is change the url from: http://localhost/test/event_info.php?id=1 to http://localhost/test/event_info/id/72/

 

thanks for the help

Link to comment
Share on other sites

You don't really explain what the problem is, assumably it's not working for you. Firstly your understanding (like 90% of peoples) seems to be a little backwards. The first half of a RewriteRule is what matches against what is requested by the clients browser i.e the address the user sees in the address bar. The second half corresponds to the file which you wish to show the user. Therefore assuming there are no errors in your rule, if you were to type http://domain/event_info/id/10 into the address bar, then the user would see the same page as if they typed in http://domain/event_info.php?id=10. This means that you need to change all URLs in your site to the 'pretty' format e.g. event_info/id/10.

 

Secondly, ideally you will need to be more specific with your regular expressions. You should anchor the pattern at the start and the end and avoid using . as much as possible. Assuming an ID is numeric then I would use a rule along the lines of...

 

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

 

NB: The forward slash before the event_info may not be required, it depends on exactly where the rule is being written. If you get a 404 without it, try adding it in as I did.

Link to comment
Share on other sites

As I said, you are not understanding how it works. This mod_rewrite rule will not change your URL at all, that is not what making 'pretty URLs' is all about. It will simply Alias the address so you can access it with a different URL. If you can type http://localhost/test/event_info/id/1 into your address bar and see the same page as if you type http://localhost/test/event_info.php?id=1, then it is working fine.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.