Forum Moderators: phranque

Message Too Old, No Replies

web-page.html to /web-page/

         

ssandecki

3:57 pm on Aug 27, 2010 (gmt 0)

10+ Year Member



Hey Everyone,

This is my first post and hopefully someone can help me out with this simple problem. One of my websites is built around Wordpress for the CMS capabilities with it's page system; however, WP is accepting the performance value of my site.

I've gone ahead and built static web pages and ready to roll them out, however I don't know how to set the .htaccess to show the right URLs. Since Wordpress permalink system allows you to make specific URLs I'll need to set my new .htaccess to match these URLs. Basically, I need to change via the example below...

Change from: http://www.site.com/web-page.html
Change to: http://www.site.com/web-page/


Now, since Google already has these indexed I don't believe I need to do a 301, I simple need the pages to be viewed as /web-page/ instead of web-page.html, hopefully someone can help me out; all opinions are appreciated!

jdMorgan

6:15 pm on Aug 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One of those two "paths" used to be the URL and is now only a filepath.
The other is the new URL that you want the pages to requested by.

Which is which?

Jim

ssandecki

6:25 pm on Aug 27, 2010 (gmt 0)

10+ Year Member



Ok, with my corrent wordpress setup the actual existing file path is..

http://www.site.com/web-page/


So, that's what search engines and all my links point to, web pages in a directory format. However, my new static pages are in php extension format as seen below...

http://www.site.com/web-page.html


So basically, I just want browsers, search engines, etc to continue seeing the web pages in directory forward (1st example above) as if nothing ever changed.

Hope this made more sense; it didn't to me for some reason! :D

jdMorgan

8:06 pm on Aug 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And is it true that you already have in place a rewrite (provided by WP, perhaps?) that rewrites requests for the URL [site.com...] to the filepath /web-page.html ?

BTW, .htaccess cannot 'make' or 'change' a URL. It can either redirect one URL to another, or it can change the filepath that is associated with that URL. However, URLs are defined by links on HTML pages, and 'exist' as soon as a link is published, whether or not the link actually resolves to an existing resource on an existing host anywhere.

So, we can redirect requests for "old-URL" to "new-URL" and we can rewrite "new-URL" to "physical filepath," but the URLs won't change unless you modify your scripts and/or edit your static HTML pages.

Jim

ssandecki

10:14 pm on Aug 27, 2010 (gmt 0)

10+ Year Member




# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress


Sadly that's the above Wordpress .htaccess and doesn't help my static files. So, I guess I would want to redirect (301?) my static html files to the actual directory name they used to be. I can use an example to figure it out for all my static files can some make the following example.

Redirect:
http://www.site.com/web-page.html


TO:
http://www.site.com/web-page/

jdMorgan

1:42 am on Aug 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, it's likely you've got this backwards, then. All you'll need is the bog-standard "extensionless URL to filepath+extension" rewrite, the WordPress rewrite performance enhancements already much-discussed here, and a "fixer" redirect rule to speed up search engines' indexing of your new extensionless URLs:

RewriteEngine on
RewriteBase /
#
# Externally redirect direct client requests for old .html-extension URLs to new extensionless URLS
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/?#\ ]+/)*[^.?#\ ]+\.html\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.html$ http://www.example.com/$1/ [R=301,L]
#
# Index URL and hostname canonicalization redirect rules (if any) must go here (in that order).
#
# Internally rewrite requested extensionless URL to .html file if the .html
# file exists and no directory physically exists at the requested URL
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(([^/]+/)*[^./]+)/$ /$1.html [L]
#
# BEGIN Enhanced WordPress
RewriteCond $1 !(^index\.php|\.(gif|jpe?g|png|ico|css|js))$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php [L]
# END Enhanced WordPress

With the "Enhanced WP code," you should notice a 15% to 25% speedup of WordPress page loading on a typical shared server.

Since you have opted to use trailing slashes on your new URLs, there is the possibility of "collisions" with the names of real subdirectories on your server. So the second rewritecond in the second rule gives precedence to physically-existing directory names, and will not rewrite to your .html page if a directory having the same name as your extensionless URL exists.

The file- and directory-exists checks in the second new rule and the WP rule are expensive in terms of CPU time and wear-and-tear on your hard drive. This is also the reason for the enhancements to the WordPress rewriterule: The "exists" checks are now avoided when they are unnecessary or when rewriting to the WP script would be fruitless.

For the same reason, you should consider eliminating the trailing slash from your extensionless URLs. This would allow you to eliminate the directory-exists check done by the second RewriteCond in the second rule (both new rules would need a few additional minor adjustments to eliminate the trailing slashes).

Jim

ssandecki

2:42 am on Aug 28, 2010 (gmt 0)

10+ Year Member



Thanks,

But, the issue is I'm "not using wordpress anymore" and I'm going to use static html files; so basically I just need the htaccess file make extension-less files "with /" since I don't have any directories.

jdMorgan

2:50 am on Aug 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



.htaccess files don't make URLs, links do. See second reply above.

Jim