Solved

Help with Rewrite

Posted on 2006-06-24
3
217 Views
Last Modified: 2010-03-04
I had asked another question related to Mod Rewrite, and after answering it julianmatz started helping me with actually implementing the Rewrite. I decided to open up another question to handle this specifically so that I can award the necessary points for this seperate issue.

Here is what julianmatz had written:

            RewriteEngine On
            RewriteRule ^viewpost([0-9]*)\.html$ /index.php?viewpost=$1 [R=301,L]

            The "R" flag will cause the page to redirect and the "=301" will cause a permanent redirect (the one you should always use to keep search engines happy).

             If you just want to rewrite the URL without the redirect, you can simply leave out the "R" flag...


So basically if I leave out the stuff in the brackets at the end, then any links to discussion.php/viewpost=15.html will automatically display the page located at discussion.php?viewpost=15 without actually redirecting the browser (the URL will still display the html link in the browser window)?
0
Comment
Question by:jfredrickson
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
Julian Matz earned 500 total points
Comment Utility
Hi jfredrickson :)

Yes, but you can make the URLs even friendlier, like in my example.

You could use the the URL
www.example.com/discussion/viewpost15.html
to serve the URL
www.example.com/discussion.php?viewpost=15

Here is the code for your .htaccess file:


Options +FollowSymlinks
RewriteEngine On
RewriteRule ^discussion/viewpost([0-9]+)\.html$ /discussion.php?viewpost=$1 [L]


Whatever number is after "viewpost" will be used for ?viewpost=[number] when serving the real URL.
The [L] flag will stop the rewriting after the first rule if the conditions are met... This is useful when using more than one RewriteRule...

Hope this helps...

-Julian.
0
 
LVL 4

Author Comment

by:jfredrickson
Comment Utility
That sounds perfect. I was afraid that this was going to be a big hurdle in the development of my site since I have never worked with this kind of stuff before, but now it seems to be all solved in a couple of minutes.

You don't know how thankful I am for this!
0
 
LVL 21

Expert Comment

by:Julian Matz
Comment Utility
You're very welcome! I'm glad I could help!

I was new to this a couple of months ago also and found it a little difficult to understand, but as with most things, practice makes perfect :) It always seems like quite a hurdle when starting off though...
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now