?
Solved

Help with Rewrite

Posted on 2006-06-24
3
Medium Priority
?
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
Julian Matz earned 2000 total points
ID: 16977067
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
ID: 16977070
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
ID: 16977080
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

800 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