I need rewrite help

Hi.

In htaccess, I’m trying to clean up my URLs and am having trouble. I know that I need to put “RewriteEngine On” which is a start. I think the reason why I’m having a hard time is because all the tutorials I have come across are made for going through just one folder, but in my case I got 2 to go through until you get to a particular article.

In short, I want to make the changes like so:

Before: [noparse]http://www.mgswalkthroughs.com/category/newsarticle.php?record=14[/noparse]
After: [noparse]http://www.mgswalkthroughs.com/category/newsarticle/14[/noparse]

Please help.


RewriteEngine On
RewriteRule ^newsarticle/([^/]*)$ /category/newsarticle.php?record=$1 [L]

^ what he said.

Although ([0-9]+) would be better (i.e. more correct) than ([^/]*) :slight_smile:


RewriteEngine On
RewriteRule ^newsarticle/([0-9]+)$ /category/newsarticle.php?record=$1 [L]

Hmm both of them didn’t seem to work.

I think it must have something to do with my hosting company, HostGator. Thanks for the help though.

Try this:


Options +FollowSymLinks

RewriteEngine On
RewriteBase /
RewriteRule ^/?newsarticle/([0-9]+)$ /category/newsarticle.php?record=$1 [L]

If that doesn’t work I’m out :slight_smile:

Still nothing. I’m pretty sure it’s my hosting. Unless I’m suppose to change the link, but I’m sure it’s suppose to do it on it’s own?

No you ~ are ~ supposed to change the links. Apache only makes sure your new urls work; it doesn’t rewrite your html.

So instead of


newsarticle.php?record=<?php echo $row_mgsnews['id']; ?>

I put:


newsarticle/<?php echo $row_mgsnews['id']; ?>

?

Sorry I’m new to this lol

yes, that looks right :slight_smile:

Well it’s not working sir :frowning:

I applied the news link in the titles for now (instead of the “Read More” buttons). It just goes to a messed up version of my 404 page.

Could you please try the test described on Apache’s mod_rewrite to see if mod_rewrite is working on your server?