0

What I'm trying to do is rewrite a few of the words in my URL from an old project module so that they look applicable to the current project.

The URL I am starting with is:

http://WEBSITE.com/stories/topic/view/pet_id/6/topic_id/41

What I have in .htaccess is:

# Change Pet and Topic to Story and Chapter
  RewriteCond stories/topic/view/pet_id/([A-Za-z0-9-]+)/topic_id/    
  RewriteRule stories/topic/view/pet_id/6/topic_id/.*$  stories/chapter/view/story_id/6/chapter_id/$1

Didn't add a part for the number on the end to conditions, since i really only needed the words changed up to that point. Not sure if that is okay or not either.

Not sure what I'm not wrong, and hope one of the mod_rewrite gurus out there can help me out. Thanks!

Kotoku
  • 15
  • 4

1 Answers1

0

Try:

RewriteRule ^(.*)/pet_id/(.*) /$1/story_id/$2 [L]  
RewriteRule ^(.*)/topic_id/(.*) /$1/chapter_id/$2 [L]  

Remove the rules you have before, not sure what they were trying to do, but they won't work. The RewriteCond doesn't do anything except break apache.

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • Hmm, gave it a shot and I get an internal error 500 page on my entire site when I do that. `# Rewrite pet to story etc` `RewriteCond stories/topic/view/pet_id/([A-Za-z0-9-]+)/topic_id/` `RewriteRule ^(.*)pet_id/(.*) /$1/story_id/$2 [L]` `RewriteRule ^(.*)topic_id/(.*) /$1/chapter_id/$2 [L]` Do I need to change my Rewrite Condition? – Kotoku Aug 26 '12 at 23:20
  • @Kotoku get rid of all of your rules before they're broken. See edit – Jon Lin Aug 26 '12 at 23:27
  • Thanks for the tips Jon! Ran it through, checked the output, and it all looked good. (Debugger told me to remove the L after the first line or it would stop and not apply the second condition). Says my output URL should be: http://website.com/stories/topic/view/story_id/4/chapter_id/8 Doesn't work as of yet, I think I might have to edit the code next if I want to fix that, since those were the names of variables? Appreciate you helping me work out the .htaccess errors at least, just curious if that is my next stop or not. – Kotoku Aug 27 '12 at 03:35
  • @Kotoku *"since those were the names of variables?"* No idea what you mean by this. I have no context of what you're doing, just that you had a URI that needed to be changed from one thing to another. If that's not working, what URI have you've ended up with that isn't what you're expecting? – Jon Lin Aug 27 '12 at 03:39
  • @Kotoku Also, don't know what debugger you are using, but the `L` flag only stops rewriting *in the current loop*. The rewrite engine will continue to loop through *all the rules* until there is no change in the URI. So leaving the `L` will only affect the order the changes are made, not change the outcome. – Jon Lin Aug 27 '12 at 03:41
  • Sorry about that, does sound funny without context. Basically I have a page that lists out all these topics (which I was trying to rewrite to chapters). So it would have a link to: http://localhost/se2/stories/topic/view/pet_id/4/topic_id/8 So when I rewrite the URI, it should be working, the rules look fine, but I'm guessing since the code is passing "pet_id" to the next page, since its dynamic, that I can't seem to replace it in the URI without modifying the PHP code itself. Your help was very good on mod_rewrite, just don't know if I can use it in this case after all. – Kotoku Aug 27 '12 at 04:08
  • I used the .htaccess checker at http://htaccess.madewithlove.be/ which is a handy little tool, and fed the rule through it to troubleshoot before I commented back again, in the context of my .htacess, to see if it had any issues. – Kotoku Aug 27 '12 at 04:15