Forum Moderators: phranque

Message Too Old, No Replies

redirect problem

         

flutence

12:39 pm on Sep 17, 2008 (gmt 0)

10+ Year Member



Hi all,

I've been browsing the forums for a while looking for an answer to this problem. Hope anyone can help

I'm using the following htaccess redirect so that a static .htm file redirects to its dynamic php file:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /[^.]+\.htm\ HTTP
RewriteCond %{REQUEST_URI} !^/encyclopedia/index.php?title=
RewriteRule ^(.*)\.htm$ /encyclopedia/index.php?title=$1 [R]

This works fine with files such as FIFA.htm or Chelsea_FC.htm

But it doesn't work with Chelsea_F.C..htm or F.C._Barcelona.htm

I imagine this is because the navigator believes that the extension is not .htm

How do I get around this? Thanks

jdMorgan

1:24 pm on Sep 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is caused by the periods in the "F.C." parts of these URLs. Also, the second RewriteCond is not needed, since the RewriteRule will only be applied to .htm URLs, and not to .php URLs. Furthermore, the REQUEST_URI variable will never contain any query string attached to the URL, so this RewriteCond will always be evaluated as "true" (since it is a negative match).

I'd suggest:


RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+htm\ HTTP
RewriteRule ^(.+)\.htm$ /encyclopedia/index.php?title=$1 [R=301,L]

Finally, look at the 'big picture' here. Do you really want to externally redirect these URLs, and expose your dynamic URL to clients? This will result in the dynamic URL replacing the static URL in search engine listings, and being visible to users in their browser address bar. 99.9% of all Webmasters posting in this forum would not want to do that, so I'm asking... The code above is the right answer, but possibly to the wrong question.

The normal procedure is to use static URLs in your on-page links, internally rewrite those static URLs (when requested from your server) to the dynamic filepath needed to properly invoke your script, and then externally redirect any direct client requests for the dynamic URL back to the static URL, so that search engines display the nice clean static URL in search results.

This process is described fully in this thread [webmasterworld.com] in our forum library.

Jim