php url_rewrite to htm

New to mod_rewrite? This is a good place to start.

php url_rewrite to htm

Postby myliferetreat » Fri Aug 07, 2009 10:27 am

First thanks for offering this forum. I spent countless hours browsing. However have not been able to get my url rewrite to work.


My current format on my site is:
http: //www. site.com/RandomCategory.php
http: //www. site.com/RandomCategory.php?page=2
http: //www. site.com/RandomCategory.php?page=3
http: //www. site.com/RandomCategory.php?page=4



I would like it to appear:
http: //www. site.com/category.htm
http: //www. site.com/page2/RandomCategory.htm
http: //www. site.com/page3/RandomCategory.htm
http: //www. site.com/page4/RandomCategory.htm


or possibly something like this which ever is easier:

http: //www. mysite.com/category-page2.htm



I have tried several url rewrite but nothing is working. Can someone help??
myliferetreat
 
Posts: 4
Joined: Fri Aug 07, 2009 10:13 am

Postby richardk » Fri Aug 07, 2009 1:46 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^category\.htm$                    /RandomCategory.php         [QSA,L]
RewriteRule ^page([0-9]+)/RandomCategory\.htm$ /RandomCategory.php?page=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby myliferetreat » Fri Aug 07, 2009 3:55 pm

It did not work.


RandomCategory.php changes
it also sometimes may include numbers such as RandomCategory911.php or Random1Category.php etc

It has pagination so therefore the page number automatically changes if the first page is full of information it goes on to page 2, 3, 4 etc.



My site has various categories but they all use the same format

My current format on my site is:
http: //www. site.com/RandomCategory.php
http: //www. site.com/RandomCategory.php?page=2

=====================
I've also tried the following mod_rewrite however it did not work

RewriteEngine on
RewriteRule ^page(.*)/(.*)\.htm$ $2.php?page=$1 [L]
RewriteRule ^(.*)\.htm$ $1.php [L]


Was trying to get this results:

http: //www. site.com/test.htm
http: //www. site.com/page2/test.htm


===========================

Also tried these options but again none of them worked

If you have mod_rewrite enabled on an Apache server, turn it on with this (in your .htaccess file):

Code:
Options +FollowSymlinks
RewriteEngine On


To change from yoursite.com/category.php to yoursite.com/category.htm:
Code:

RewriteRule ^([a-z0-9_-]+).htm$ /$1.php [L]

To change from yoursite.com/category.php?page=2 to yoursite.com/page#2/category.htm:
Code:
RewriteRule ^page#([0-9]+)/([a-z0-9_-]+).htm$ /$2.php?page=$1 [L]


To change from yoursite.com/category.php?page=2 to yoursite.com/category-page2.htm:
Code:
RewriteRule ^([a-z0-9_-]+)-page([0-9]+).htm$ /$1.php?page=$2 [L]


===================

By the way none of these options worked on my webserver
myliferetreat
 
Posts: 4
Joined: Fri Aug 07, 2009 10:13 am

Postby myliferetreat » Fri Aug 07, 2009 4:01 pm

I've just tried this option and again, Zip. Nothing!
I am not sure what I could be doing wrong. My site still goes to the php page.



Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-z0-9]+)\.htm$ /([a-z0-9]+).php [QSA,L]
RewriteRule ^page([0-9]+)/([a-z0-9]+)\.htm$ /([a-z0-9]+).php?page=$1 [QSA,L]
myliferetreat
 
Posts: 4
Joined: Fri Aug 07, 2009 10:13 am

Postby richardk » Fri Aug 07, 2009 4:16 pm

I am not sure what I could be doing wrong. My site still goes to the php page.

Mod_rewrite does not change the links outputted by your script. What happens when you type /page2/RandomCategory.htm in the address bar of your browser.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}/$1php -f
RewriteRule ^([^/]+\.)htm$              /$1php         [QSA,L]

RewriteCond %{DOCUMENT_ROOT}/$2php -f
RewriteRule ^page([0-9]+)/([^/]+\.)htm$ /$2php?page=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby myliferetreat » Fri Aug 07, 2009 4:57 pm

Ok. I never actually attempt to visit the site with the .htm format.. So here's the results now. The site loads but here's the problems.

when I visit my site as

http: //www. site.com/RandomCategory.htm
http: //www. site.com/RandomCategory.php

it does load up in the .htm... I can actual access the page with both formats .php and .htm


Could this be a duplicate content issue with google??

Now here the problem with the paginations

when I visit my site as

http: //www. site.com/page#/RandomCategory.htm the page loads however my images does not load

again same thing I can access the page with both .php and .htm

Same question would this be a duplicate content issue with google.

So I suppose my issues now would be how to make it where google only see the .htm page only.

I want it where my visitors go to my site they are automatically sent from the php file to the htm file and as of now that doesn't work. If I go to the php file. Thats the file that loads and if I go to the htm file that the file i see.

I hope I am not confusing you....

Thanks for your
myliferetreat
 
Posts: 4
Joined: Fri Aug 07, 2009 10:13 am

Postby richardk » Wed Aug 12, 2009 11:24 am

Could this be a duplicate content issue with google??

Probably.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{SCRIPT_FILENAME} -f
RewriteCond %{QUERY_STRING} ^(.*&)?page=([0-9]+)(&.*)?$ [NC]
RewriteRule ^([^/]+\.)php$ /page%2/$1htm [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule ^([^/]+\.)php$ /$1htm [R=301,L]

RewriteCond %{DOCUMENT_ROOT}/$1php -f
RewriteRule ^([^/]+\.)htm$ /$1php [QSA,L]

RewriteCond %{DOCUMENT_ROOT}/$2php -f
RewriteRule ^page([0-9]+)/([^/]+\.)htm$ /$2php?page=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 32 guests

cron