Solved

Help with Rewrite

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 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

12 Experts available now in Live!

Get 1:1 Help Now