Solved

Help with Rewrite

Posted on 2006-06-24
3
219 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 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

15 Experts available now in Live!

Get 1:1 Help Now