The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
PHP-General - Rewrite URLs to be SEO Friendly
Discuss Rewrite URLs to be SEO Friendly in the PHP Development forum on Dev Shed. Rewrite URLs to be SEO Friendly PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 23rd, 2013, 03:00 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 2
Time spent in forums: 35 m 2 sec
Reputation Power: 0
|
|
|
PHP-General - Rewrite URLs to be SEO Friendly
Looking for advice on how to properly rename the URLs on my website to be SEO friendly. The website is PHP with an .htaccess folder in the admin panel. I'm not a PHP guru, but I know a little about editing code.
I'd like to use the best method that is SEO friendly.
Any suggestions?
|

January 23rd, 2013, 03:53 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 1
Time spent in forums: 6 m 22 sec
Reputation Power: 0
|
|
|
The best way is using dash separated keywords like
category-name/current-page-title
|

January 23rd, 2013, 04:19 PM
|
 |
Contributing User
|
|
Join Date: Nov 2012
Posts: 98
Time spent in forums: 1 Day 2 h 20 m 38 sec
Reputation Power: 1
|
|
- Keep your rewritten URL's directories to a maximum of 2-3 for SEO (i.e.. example.com/dir1/dir2
- You can appened .html to the end of your main pages (i.e.. example.com/dir1/final_destination.html)
- Use Keywords in your URLs, that are also present in your content. (i.e.. example.com/articles/article-or-news-title.html)
- Use dashes in your URL's and not underscores. Search engines recognize dashes as spaces
- Keep your directories in your URL's open without a trailing slash for pages that just lead to yet another page (i.e.. example.com/category1/morecategoriesafter
- Follow a consistent URL naming scheme throughout your entire site. Break out the pad of paper and pencil and design a naming scheme that you can follow. Plan, prepare, execute.
Also, I think this thread would do better in the Search Engine Optimization section of this forum.
__________________
-- Success achieved from tribulation --
Last edited by BitZoid : January 23rd, 2013 at 04:25 PM.
|

January 24th, 2013, 09:36 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 2
Time spent in forums: 35 m 2 sec
Reputation Power: 0
|
|
|
Thanks for the advice, but I need to understand how to do the rewrite properly.
1. Would I use the following code to 301 w.cityofficespaces.com/default to w.cityofficespaces.com ?
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^w.cityofficespaces.com/default [nc]
rewriterule ^(.*)$ w.cityofficespaces.com/$1 [r=301,nc]
2. How would I rewrite w.cityofficespaces.com/Search/SearchDetails/24 to become w.cityofficespaces.com/office-space-for-rent-new-york-city/midtown-west/24 ?
Thanks,
David
|

January 24th, 2013, 11:23 AM
|
 |
Square Peg in a Round Hole
|
|
Join Date: Oct 2007
Location: North Yorkshire, UK
|
|
One issue many newbies to .htaccess rewritning stumble on is this:
.htaccess and php don't talk to each other, so just adding URL rewriting to .haccess does not automagically rewrite the outgoing html - you have to do this in your templates.
.htaccess rewriting is for rewriting the incoming requests from a request that does not match a file to a request that does match a file
eg when a user requests
http://www.example.com/friendly/link.html
then the server actually gets
http://www.example.com/index.php?q=friendly/link.html
(for example)
This can be achieved with
Code:
#turn on rewrite engine
RewriteEngine On
#operate on web root
RewriteBase /
#if the request is not an existing file, continue
RewriteCond %{REQUEST_FILENAME} !-f
#if the request is not an existing directory, continue
RewriteCond %{REQUEST_FILENAME} !-d
#do a rewrite.The L option means that no further rules should be processed after this one, if this one executes
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
#(can't remember what the QSA options are about;) )
your templates would then need to make the links to
http://www.example.com/friendly/link.html
instead of
http://www.example.com/index.php?page_id=8
Last edited by Northie : January 24th, 2013 at 11:28 AM.
Reason: additional code and comments
|

January 24th, 2013, 12:38 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
Quote: | Originally Posted by BitZoid Also, I think this thread would do better in the Search Engine Optimization section of this forum. |
Back when we thought he wanted advice about what they should look like, yes, but since the question is apparently about how to do it this thread here is fine.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|