sitemap not redirecting

Discuss practical ways rearrange URLs using mod_rewrite.

sitemap not redirecting

Postby saieditor » Fri Aug 01, 2008 1:08 am

I just trying to get something to work so that search engines and the sitemap do the right thing.

The folder concerned is populated with php files replacing html files.

My rewrite is

Code: Select all
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^youth/([a-z]+)\.html$ /youth/$1.php [R=301,L]


But the sitemap will not redirect from html to php ...?

Any ideas where I might be going awry?
saieditor
 
Posts: 5
Joined: Fri Aug 01, 2008 12:49 am

Postby richardk » Fri Aug 01, 2008 3:55 pm

What sitemap? A HTML page, one for search engines?

Mod_rewrite does not change the URLs in file, it works on the incoming request only.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby saieditor » Thu Aug 14, 2008 1:09 am

What I understood my rewrite did was to redirect all requests for files with html extension in a sub folder to the same file with a php extension.

Will the example I have given do this?

My only way of testing was to use the html page I use for a site directory (which I have not changed) to see what file it would load.

It appears to be only working on the index file in that folder. All other files get a 404

:o
saieditor
 
Posts: 5
Joined: Fri Aug 01, 2008 12:49 am

Postby richardk » Sat Aug 16, 2008 3:18 pm

Where are you putting the mod_rewrite?

Try in your document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^youth/([^/]+)\.html$ /youth/$1.php [R=301,L]

or if you are putting it in /youth, replace
Code: Select all
^youth/([^/]+)\.html$

with
Code: Select all
^([^/]+)\.html$
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby saieditor » Sun Aug 17, 2008 10:56 am

Many thanks, Richard.

Worked like a dream. :D
saieditor
 
Posts: 5
Joined: Fri Aug 01, 2008 12:49 am

Postby saieditor » Sun Mar 08, 2009 10:11 pm

I am doing the same thing on another site now, (converting html to php) and using the above rewrite script to deal with the subfolders, i.e, french, german, polish, japanese, etc.

I have also converted all the root folder html files to php.

How do I rewrite the root folder to redirect calls for html to php?
saieditor
 
Posts: 5
Joined: Fri Aug 01, 2008 12:49 am

Postby richardk » Mon Mar 09, 2009 6:58 am

If you want to do that for all .html requests you can use
Code: Select all
Options +FollowSymLinks

RewriteEngine On

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

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

Postby saieditor » Mon Mar 09, 2009 1:55 pm

Many thanks for your help there Richard.

It all makes sense when you code it like that. :D
saieditor
 
Posts: 5
Joined: Fri Aug 01, 2008 12:49 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 25 guests

cron