944,123 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 99532
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jun 27th, 2005
0

URL Rewrite in PHP

Expand Post »
Is there any way I can convert dynamic URL into static URL in php? i.e. convert php file into html so that the page is search engine friendly. For example:

Change this: http://mysite.com/pagename.php
To this: http://mysite.com/pagename
or this: http://mysite.com/pagename.html

I know there is something called mod_rewrite in Apache, but not sure how it works and whether it's related to what I want.

Thanks for any comment.
Similar Threads
Reputation Points: 10
Solved Threads: 7
Posting Whiz in Training
zippee is offline Offline
294 posts
since Jan 2005
Jun 27th, 2005
1

Re: URL Rewrite in PHP

Yes, mod_rewrite is what you want if you are using Apache.

If anybody has any proof, I'd like to see it, but the official word from Google and others is that data-driven content (.ASP, .PHP, .JSP, etc.) is not a problem for their spiders. The only problem for spiders associated with data-driven pages is speed. A spider obviously "browses" your site a lot faster than a human. It may request a dozen pages in a single second. Spiders are not as patient as most humans, either. If your page takes 5 seconds to return--whether static or data-driven, the spider may consider the link bad and move on.

My point is that jumping through hoops to make your data-driven pages LOOK like static pages doesn't help your pages load any faster--which is the real issue with search engines--at least Google anyway.

Google has a Facts & Fiction page here that explains they can index dynamic pages.
http://www.google.com/webmasters/facts.html

At least for google, querystrings are not an issue either, although they do recommend you keep your querystrings short with only a few parameters.

Another "secret" is that if the only way to get to your pages is via a search on your site, then a spider will never find them. You do need every page that you want indexed somehow linked from another page. For example, if your site sells fruit, and the only way for me to reach your fruit_detail.php?fruit=apple page is by searching your inventory for "apple", then a bot will not find this page. However, if I can click on "Inventory" in your menu, then click "Apples" on your page listing all the fruit you sell, a bot can follow these links, too. (This assumes your menu is not generated by javascript, does not require javascript to navigate, and is not a Flash movie menu.)

This is a huge topic, and should be discussed in http://www.daniweb.com/techtalkforums/forum45.html, but one last tip I can offer is to remember you need standard links to your content. If a link has a target like <a href="javascript:LoadPage('fruit.htm')">Fruit</a>, a spider will not be able to follow this link since they cannot run client-side script.
Reputation Points: 36
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005
Jun 27th, 2005
0

Re: URL Rewrite in PHP

Troy, that's really helpful!

I realise the search engine can search through dynamic site, but not many people convince about this, especially those non-programmers. this is why I try to have html version to convince my clients.
Reputation Points: 10
Solved Threads: 7
Posting Whiz in Training
zippee is offline Offline
294 posts
since Jan 2005
Jun 27th, 2005
0

Re: URL Rewrite in PHP

I developed an ASP site for a client years ago. The site is still in use today. It is an ASP site using a SQL Server database. The site has only 5 ASP scripts that produce over 250 data-driven pages. So all the "page" URLs are similar to trip.asp?S=14&L=57. Although the pages load very fast, I read that search engines may not search ASP pages, so I wrote a powerful (but surprisingly simple) script that generates a static HTML site from the ASP site. It crawls the site like a spider and generates a static .htm version of every dynamic page. Now, about once a week, the client runs the "generate static site" utility to update the site with recent data changes. The result is that I've not seen any improvement in search engine ranking. The site was indexed before, just 100s of hits down in the results. This has not changed.

I know there is a lot more to SEO than static vs dynamic, but my point is that in my experience and from what I read from Google, static vs dynamic does not matter.
Reputation Points: 36
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005
Jun 27th, 2005
0

Re: URL Rewrite in PHP

They "prefer" .html pages over dynamic pages, but Google doesn't care, they spider forums just fine, take a look at vBulletin.com for example, ALOT is indexed
Team Colleague
Reputation Points: 96
Solved Threads: 21
The Geek Father
Zachery is offline Offline
781 posts
since Nov 2003
Jun 28th, 2005
0

Re: URL Rewrite in PHP

Quote originally posted by zippee ...
Change this: http://mysite.com/pagename.php
To this: http://mysite.com/pagename
or this: http://mysite.com/pagename.html
http://mysite.com/pagename
http://mysite.com/pagename.html

Both will work in mod_rewrite.

As for http://mysite.com/pagename, try
RewriteRule ^pagename pagename.php

As for http://mysite.com/pagename.html, try
RewriteRule ^pagename.html pagename.php

There is an another option you can also try called php pathinfo. http://www.tutorio.com/tutorial/php-...-friendly-urls

Hope it helps.
PoA
Reputation Points: 19
Solved Threads: 9
Posting Whiz in Training
PoA is offline Offline
234 posts
since Jul 2004
Apr 23rd, 2009
0

Re: URL Rewrite in PHP

An example of how to write a simple rewriting rule:

[URL sipped]
Last edited by Ezzaral; Apr 23rd, 2009 at 4:03 pm. Reason: Snipped url. Keep it spam-free.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
a-geek is offline Offline
1 posts
since Apr 2009
Apr 23rd, 2009
0

Re: URL Rewrite in PHP

Click to Expand / Collapse  Quote originally posted by a-geek ...
An example of how to write a simple rewriting rule:

[URL snipped]
4 year bump! Drink!
Last edited by Ezzaral; Apr 23rd, 2009 at 4:04 pm. Reason: Snipped url from quoted message.
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Aug 12th, 2010
0
Re: URL Rewrite in PHP
i understand that but can anyone tell me how i can get value on next page...
means... my real url was movile.php?movieid=$mid[0] but i have change this one to moviename.html with the help of url rewrite rule... but now tell me how can i get movieid on next page while no id is in new url....
Last edited by UNDiL; Aug 12th, 2010 at 4:57 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
UNDiL is offline Offline
1 posts
since Aug 2010
Sep 2nd, 2010
0
Re: URL Rewrite in PHP
Click to Expand / Collapse  Quote originally posted by PoA ...
http://mysite.com/pagename
http://mysite.com/pagename.html

Both will work in mod_rewrite.

As for http://mysite.com/pagename, try
RewriteRule ^pagename pagename.php

As for http://mysite.com/pagename.html, try
RewriteRule ^pagename.html pagename.php

There is an another option you can also try called php pathinfo. http://www.tutorio.com/tutorial/php-...-friendly-urls

Hope it helps.
May I ask : what if I want all my result pages url without extension?? What should I put as rule?
RewriteRule ^???? ?????.php

thanks
Reputation Points: 10
Solved Threads: 2
Newbie Poster
didier_m is offline Offline
20 posts
since Aug 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: how to get selected values from a form loop
Next Thread in PHP Forum Timeline: Passing variables to SQL statements...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC