homepage Welcome to WebmasterWorld Guest from 54.211.201.65
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Extensionless URLs
bluewaves




msg:4548442
 9:37 pm on Feb 24, 2013 (gmt 0)

I found coding that will drop my .php extension on any page with a .php extension. Works fine.

So now, when I am hard coding the pages, do I use the extensionless urls?

Do I put the extensionless urls in my sitemaps?

I am just wondering about duplicate content penalties resulting from this.

 

Andy Langton




msg:4548443
 9:40 pm on Feb 24, 2013 (gmt 0)

The solution is simple enough - redirect from the .php extension to the extensionless URL.

The general practice is to determine the 'canonical' URL - the one that you will use in your internal links, sitemaps, and indeed, everywhere. Then force that format via permanent (301) redirects.

The redirects can be achieved with mod_rewrite. The output of the links is down to your PHP scripts.

lucy24




msg:4548512
 2:53 am on Feb 25, 2013 (gmt 0)

So now, when I am hard coding the pages, do I use the extensionless urls?

If you mean: Do you save the physical file without an extension, NO. Everything has an extension. (Except, ahem, things with leading dot.) If you mean: Should internal links on your own pages give the extensionless form, YES.

Do I put the extensionless urls in my sitemaps?

Again YES. Your sitemap lists URLs, not physical location. Search engines should not even know the .php form exists.

The formula has been given in several thousand earlier threads in this forum. It goes

R
ewriteCond %{THE_REQUEST} real-name-here
RewriteRule real-name-here made-up-name-here [R=301,L]

RewriteRule made-up-name-here real-name-here [L]

bluewaves




msg:4548516
 3:03 am on Feb 25, 2013 (gmt 0)

Thanks. All of my physical pages of course have the .php extension. The script then redirects to the pagename (without .php)

I just think I now need to change all my hardcoded links to the extensionless version - which will require a little work, but I think it will be worth it.

bluewaves




msg:4548519
 3:20 am on Feb 25, 2013 (gmt 0)

Should I be using a trailing slash in my hard coded links?

Swanny007




msg:4548534
 5:02 am on Feb 25, 2013 (gmt 0)

How long have the pages been online, and why do you want to drop the extension? Also, how many pages are you talking about? 50? 500?

It's a better practice to never change URLs if possible. In other words if they're .php, leave 'em alone, and make new pages extension-less. That's more important on older, aged content that's getting traffic.

I would not use a trailing slash as that usually indicates a folder, although it really doesn't matter.

lucy24




msg:4548547
 6:06 am on Feb 25, 2013 (gmt 0)

Should I be using a trailing slash in my hard coded links?

Only if your object is to pretend that each of your extensionless URLs is the index page of a directory that doesn't really exist. I don't think anyone hereabouts would advise you to do that.

If you use a trailing slash in one place you have to use it everywhere. Since we are not talking about real, physical directories, mod_dir will not step in and supply a missing slash.

Again: In all internal links and also in your sitemap, give the form of the URL that you want to appear in the browser's address bar.

g1smd




msg:4548558
 8:54 am on Feb 25, 2013 (gmt 0)

For pages, URLs should not end with a trailing slash.

URL with trailing slash denotes folder or index page of folder.

bluewaves




msg:4548806
 8:41 pm on Feb 25, 2013 (gmt 0)

Ok. Thank you.

bluewaves




msg:4549302
 3:27 am on Feb 27, 2013 (gmt 0)

The solution is simple enough - redirect from the .php extension to the extensionless URL. ---

So do I need to RewriteRule ^example\.php http://www.example.com/example [R=301,L] for all my pages?

lucy24




msg:4549326
 5:09 am on Feb 27, 2013 (gmt 0)

You mean, listing all the pages by name and making a separate rule for each one?

That kinda blows the point of having Regular Expressions and captures.

I think you started by saying that you already have code that rewrites in the other direction, from the php-less URL to the .php location where the content lives. Your new redirect should be the exact mirror image of this code, and should come before it in htaccess.

That's assuming your rewriting code-- which you haven't said much about-- is also happening in mod_rewrite within htaccess. Can't imagine why it wouldn't, since that part is a single conditionless RewriteRule.

g1smd




msg:4549365
 10:25 am on Feb 27, 2013 (gmt 0)

msg:4549363 in thread [webmasterworld.com...] might be useful for what all the steps are.
lucy24




msg:4549389
 11:26 am on Feb 27, 2013 (gmt 0)

And I now realize that the reason I was getting dizzy is that the same person really does have two threads going.

Whew.

g1smd




msg:4549392
 11:35 am on Feb 27, 2013 (gmt 0)

I hadn't noticed that, but had thought it had got rather busy with a lot of similar questions in the last 10 days.

bluewaves




msg:4549541
 6:46 pm on Feb 27, 2013 (gmt 0)

I apologize for starting two threads. I will just post on the other thread and I will try to ask clearer questions.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved