Forum Moderators: phranque

Message Too Old, No Replies

URL Rewrite help needed

         

pro_seo

6:24 pm on Jul 29, 2007 (gmt 0)

10+ Year Member



Friends,

I've been been trying to rewrite some of my dynamic URLs to static ones but in vain.

The URLs are like http://www.example.com/links.php?page=2
and I want to change it to static php or HTML ones.

I've tried numerous time putting rewrite codes in my htaccess but still it doesn't seem to work.

I also have a couple of 301 redirection codes in my htaccess as well

The total file looks like:

RewriteEngine on
Options +FollowSymlinks

RewriteRule links-page-(.*)\.htm$ links.php?page=$1

rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]

redirect 301 /links.php?page=2 http://www.example.com/links-page-2.html
redirect 301 /links.php?page=3 http://www.example.com/links-page-3.html

I feel I am making a mistake somewhere for which this isn't working. Kindly help me on this plzzzz...

Thanks a ton in advance!

[edited by: jdMorgan at 3:33 am (utc) on July 30, 2007]
[edit reason] example,com [/edit]

g1smd

7:35 pm on Jul 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



From what I can see, you possibly create an endless loop, and the order of some of it is incorrect. Additionally the treatment of query strings isn't correct.

# Allow Rewrites and Redirects
RewriteEngine on
Options +FollowSymlinks

# Fix up Index URLs to "/" and force www at same time
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ http://www.example.com/$1 [R=301,L]

# Externally redirect requests for Dynamic URLs to the Static equivalent and force www too
RewriteCond %{REQUEST_URI} ^links.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /links\.php\?paqe=([^&]+)\ HTTP/
RewriteRule ^links\.php http://www.example.com/links-page-%1.html [R=301,L]

# Fix non-www to www for all remaining non-www
RewriteCond %{HTTP_HOST} ^example\.com [nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

# Internally silently rewrite Static URL to Dynamic format
RewriteCond %{REQUEST_URI} ^links-page-
RewriteRule links-page-(.*)\.htm$ /links.php?page=$1 [L]

I hope this works. It is untested.

[edited by: jdMorgan at 3:35 am (utc) on July 30, 2007]
[edit reason] example.com [/edit]

pro_seo

5:14 am on Jul 30, 2007 (gmt 0)

10+ Year Member



Thanks a lot mate.

I'll definitely try this out and let you know if this works.

Thanks again :)

g1smd

1:28 am on Jul 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I suspect that my code can be optimised and simplified in several ways.

As it is untested, I am hoping there are no typos or wrong assumptions either.