PDA

View Full Version : mod_rewrite


FiRe
11-09-05, 06:01 AM
I know this isn't php/mysql but its apache related so it just about qualifies :D

I have a folder called "tutorials" and tutorial ID 25 looks like this:

www.site.com/tutorials/index.php?tutid=25

Now i have put this inside the tutorials folder in a .htaccess file:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^tutorials/(.*)$ index.php?tutid=$1

So that people can go to:

www.site.com/tutorials/25/

But I get a 404 error. I have also changed the rewrite code to this:

RewriteRule ^/(.*)$ index.php?tutid=$1

But the same error. Whats wrong with it??

End User
11-09-05, 02:38 PM
1) If you try and go to "www.site.com/tutorials/25/" in the browser you get a 404, or only when you go from a link in the script?

2) You may also want to have the rule add an extension:

RewriteRule ^tutorials/(.*).htm$ index.php?tutid=$1

The rewrite rule looks fine to me, but I'd put the htaccess file in the root.

Also, almost none of the htaccess tutorials on the web make note of the fact that you'll need to modify the code in your site or application to deliver the correctly formatted URL to the browser.

So instead of having your code output this to the browser:

www.site.com/tutorials/index.php?tutid=25

you may need to modify it so it outputs this:

www.site.com/tutorials/$tutid.htm

I recently finished doing a brutally complicated htaccess "conversion" of an existing application, and mod_rewrite is still nearly voodoo to me, lol.

Brandon@Cstone
11-09-05, 06:49 PM
I used this recently:

RewriteEngine On

RewriteRule (.*) http://www.site.com/$1 [R=301,L]
RedirectMatch 301 /item/(.*) http://www.site.com/folder/page.php?getthis=$1

Works

Brandon

End User
11-10-05, 01:26 PM
I used this recently:

RewriteEngine On

RewriteRule (.*) http://www.site.com/$1 [R=301,L]
RedirectMatch 301 /item/(.*) http://www.site.com/folder/page.php?getthis=$1

Works

Brandon
You didn't have to rewrite any of the application code to output the correct URL format to the browser?