Web Hosting Forum | Lunarpages

Author Topic: .htaccess + mod_rewrite help - trying to rewrite URLs  (Read 34725 times)

Offline RonRattie

  • Space Explorer
  • ***
  • Posts: 9
    • stillpixelstudios
.htaccess + mod_rewrite help - trying to rewrite URLs
« on: June 03, 2009, 09:04:16 PM »
I'm trying to change URLs like www.somesite.com/index.php?page=1 to www.somesite.com/index.htm or www.somesite.com/this_is_a_seo_friendly_url/

I have this

RewriteCond %{QUERY_STRING} ^page=4$
RewriteRule ^contact\.html index.php?page=4 [L]

so far, but it doesn't do anything. I have scoured the net looking for information on how to do this correctly and I am fairly frustrated. :cry:

Anyone have an idea?
stillpixelstudios - no print, just pixels

Offline Mitch

  • Berserker Poster
  • *****
  • Posts: 12641
    • MitchKeeler.com
Re: .htaccess + mod_rewrite help - trying to rewrite URLs
« Reply #1 on: June 04, 2009, 05:31:47 AM »
Hi Ron!

Are you using a specific script or CMS to control your site?
New to Web Site Hosting? Check Out the Lunarpages Blog Hosting Guide!


Follow us @lunarpages on Twitter!
Important Threads: Read This Before Posting! | Lunarforums Rules! | Mitch's Link of the Day!
Also, be sure to check out and subscribe to the Lunartics Blog and the Lunarpages Newsletter !

Need Web Hosting Help? Check out the Lunarpages Web Hosting Wiki. It has tons of tips, tutorials and resources!

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6246
Re: .htaccess + mod_rewrite help - trying to rewrite URLs
« Reply #2 on: June 04, 2009, 07:49:40 AM »
You're going in the wrong direction. Links on your pages (as well as search engine entries and bookmarks/favorites) should be of the form index.htm. Your .htaccess file should be converting index.htm to index.php?page=1 via URL rewriting. There should be no "QUERY_STRING" in the incoming URL, just "index.htm".
Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-

Offline RonRattie

  • Space Explorer
  • ***
  • Posts: 9
    • stillpixelstudios
Re: .htaccess + mod_rewrite help - trying to rewrite URLs
« Reply #3 on: June 04, 2009, 01:09:29 PM »
You're going in the wrong direction. Links on your pages (as well as search engine entries and bookmarks/favorites) should be of the form index.htm. Your .htaccess file should be converting index.htm to index.php?page=1 via URL rewriting. There should be no "QUERY_STRING" in the incoming URL, just "index.htm".

As is my nature, I posted the question but continued to search and experiment.  I have fixed/solved my problem.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^pjsroofing.com [NC]
RewriteRule ^(.*)$ http://www.pjsroofing.com/$1
RewriteRule ^<long-winded spam phrase removed>\.html index.php?page=1 [L]
RewriteRule ^<long-winded spam phrase removed>\.html index.php?page=2 [L]
RewriteRule ^<long-winded spam phrase removed>\.html index.php?page=3 [L]
RewriteRule ^<long-winded spam phrase removed>\.html index.php?page=4 [L]
RewriteRule ^<long-winded spam phrase removed>\.html index.php?page=5 [L]

Quote
Are you using a specific script or CMS to control your site?

no specific scripts were used, just straight up PHP, HTML and CSS.

It is now live at http://www.pjsroofing.com  (a client who I referred to lunarpages from the other hosting company when I was redesigning the site).
« Last Edit: January 11, 2018, 10:29:39 AM by MrPhil »
stillpixelstudios - no print, just pixels

Offline Mitch

  • Berserker Poster
  • *****
  • Posts: 12641
    • MitchKeeler.com
Re: .htaccess + mod_rewrite help - trying to rewrite URLs
« Reply #4 on: June 05, 2009, 03:17:23 AM »
Happy to hear it!   :thumb:
New to Web Site Hosting? Check Out the Lunarpages Blog Hosting Guide!


Follow us @lunarpages on Twitter!
Important Threads: Read This Before Posting! | Lunarforums Rules! | Mitch's Link of the Day!
Also, be sure to check out and subscribe to the Lunartics Blog and the Lunarpages Newsletter !

Need Web Hosting Help? Check out the Lunarpages Web Hosting Wiki. It has tons of tips, tutorials and resources!

Offline RonRattie

  • Space Explorer
  • ***
  • Posts: 9
    • stillpixelstudios
Re: .htaccess + mod_rewrite help - trying to rewrite URLs
« Reply #5 on: June 05, 2009, 04:47:43 AM »
nice edit Mitch  :notme:
stillpixelstudios - no print, just pixels

Offline Mitch

  • Berserker Poster
  • *****
  • Posts: 12641
    • MitchKeeler.com
Re: .htaccess + mod_rewrite help - trying to rewrite URLs
« Reply #6 on: June 05, 2009, 04:54:17 AM »
Hmmmm?   :-?
New to Web Site Hosting? Check Out the Lunarpages Blog Hosting Guide!


Follow us @lunarpages on Twitter!
Important Threads: Read This Before Posting! | Lunarforums Rules! | Mitch's Link of the Day!
Also, be sure to check out and subscribe to the Lunartics Blog and the Lunarpages Newsletter !

Need Web Hosting Help? Check out the Lunarpages Web Hosting Wiki. It has tons of tips, tutorials and resources!

Offline RonRattie

  • Space Explorer
  • ***
  • Posts: 9
    • stillpixelstudios
Re: .htaccess + mod_rewrite help - trying to rewrite URLs
« Reply #7 on: June 05, 2009, 07:49:23 AM »
"from the other hosting company" <===  was not what I wrote.


* - edited this as an example

note the note under this...
« Last Edit: June 05, 2009, 10:06:22 AM by Mitch »
stillpixelstudios - no print, just pixels

Offline Mitch

  • Berserker Poster
  • *****
  • Posts: 12641
    • MitchKeeler.com
Re: .htaccess + mod_rewrite help - trying to rewrite URLs
« Reply #8 on: June 05, 2009, 10:05:38 AM »
"from the other hosting company" <===  was not what I wrote.

Very odd, wasn't edited by me, I'll show you on your previous post what comes up with I edit something.
New to Web Site Hosting? Check Out the Lunarpages Blog Hosting Guide!


Follow us @lunarpages on Twitter!
Important Threads: Read This Before Posting! | Lunarforums Rules! | Mitch's Link of the Day!
Also, be sure to check out and subscribe to the Lunartics Blog and the Lunarpages Newsletter !

Need Web Hosting Help? Check out the Lunarpages Web Hosting Wiki. It has tons of tips, tutorials and resources!

Offline Mitch

  • Berserker Poster
  • *****
  • Posts: 12641
    • MitchKeeler.com
Re: .htaccess + mod_rewrite help - trying to rewrite URLs
« Reply #9 on: June 05, 2009, 10:06:58 AM »
"from the other hosting company" <===  was not what I wrote.

Very odd, wasn't edited by me, I'll show you on your previous post what comes up with I edit something.

Last Edit: Today at 01:06:22 PM by Mitch
New to Web Site Hosting? Check Out the Lunarpages Blog Hosting Guide!


Follow us @lunarpages on Twitter!
Important Threads: Read This Before Posting! | Lunarforums Rules! | Mitch's Link of the Day!
Also, be sure to check out and subscribe to the Lunartics Blog and the Lunarpages Newsletter !

Need Web Hosting Help? Check out the Lunarpages Web Hosting Wiki. It has tons of tips, tutorials and resources!

Offline Mitch

  • Berserker Poster
  • *****
  • Posts: 12641
    • MitchKeeler.com
Re: .htaccess + mod_rewrite help - trying to rewrite URLs
« Reply #10 on: June 05, 2009, 10:07:49 AM »
Either way though, happy to hear you got it taken care of.  :yey:
New to Web Site Hosting? Check Out the Lunarpages Blog Hosting Guide!


Follow us @lunarpages on Twitter!
Important Threads: Read This Before Posting! | Lunarforums Rules! | Mitch's Link of the Day!
Also, be sure to check out and subscribe to the Lunartics Blog and the Lunarpages Newsletter !

Need Web Hosting Help? Check out the Lunarpages Web Hosting Wiki. It has tons of tips, tutorials and resources!

Offline Frederickroofers

  • Newbie
  • *
  • Posts: 1
Re: .htaccess + mod_rewrite help - trying to rewrite URLs
« Reply #11 on: July 31, 2017, 10:31:33 PM »
RewriteEngine on
RewriteCond %{HTTP_HOST} ^<domain.com> [NC]
RewriteRule ^(.*)$ http://www.<domain.com>/$1
RewriteRule ^<long-winded spam phrase removed>\.html index.php?page=1 [L]
RewriteRule ^<long-winded spam phrase removed>\.html index.php?page=2 [L]

<changed non-LP-hosted domain name, otherwise it's spam -- Mod.>
<what was the question? this looks like a partial copy of RonRattie's post -- Mod.>
« Last Edit: January 11, 2018, 10:30:54 AM by MrPhil »

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6246
Re: .htaccess + mod_rewrite help - trying to rewrite URLs
« Reply #12 on: January 11, 2018, 10:41:19 AM »
I just cleaned up an older post, and a partial copy of it, that was spam (although for an LP-hosted site, so it wasn't totally removed). There were two problems with these rewrites, such as
Code: [Select]
RewriteRule  ^talk_to_us_about_our_low_low_prices_and_highest_quality_workmanship_with_name_brand_materials_today_and_not_tomorrow\.html index.php?page=4 [L]
First of all, no one is ever going to type in a file name that long. The idea is to have a product name or a couple of choice keywords, and not a full sales pitch. Secondly, SEO won't help you because words separated by underscores _ are treated as one long word, and a potential customer would have to type the whole thing in exactly. You would want to separate words by hyphens - so that search engines recognize the separate words!
Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-

 

Share |