Solved

Help with Rewrite

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

724 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