adambedford Posted July 4, 2010 Share Posted July 4, 2010 I'm working with an old site that is made up of entirely static html pages and I'm under strict instruction not to change the URLs at all (for SEO purposes). Pages are named like this: costa-blanca-villas.html and costa-blanca-3-bedrooms.html whereby the costa-blanca-villas.html is the parent page with links to the various sub-pages for each bedroom category. Now I'm certain I can work with this structure and still develop a new, dynamic site, but I don't know how to go about the mod_rewrite complication. Any suggestions? The pages are all consistently named as above with varying regions of Spain and numbers of bedrooms so I think I would need to forward to a new php page and pass the info along in a query string. I understand how to do this if the pages were named "villas/costa-blanca/3/" for example but I dont know how to deal with parsing the format they're in currently. Also, how would I go about ignoring the ".html" extension? Any help would be greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/206665-a-tricky-rewrite-situation/ Share on other sites More sharing options...
premiso Posted July 4, 2010 Share Posted July 4, 2010 Whats wrong with parsing just the word? RewriteRule ^path/([a-z])-([a-z])-([a-z])\.html$ path/to/file.php?var1=$1&var2=$2&var3=$3 [L] Something along those lines. So using that you do not need to change anything really. You just have to test out the right combination and it may take multiple rewrites depending on what pages etc are setup right. Quote Link to comment https://forums.phpfreaks.com/topic/206665-a-tricky-rewrite-situation/#findComment-1080883 Share on other sites More sharing options...
adambedford Posted July 4, 2010 Author Share Posted July 4, 2010 That looks like a pretty simple solution, thank you! I'm trying to future proof the site as much as possible so that other regions can be added at a later date. These might have varying number of words (ie. "costa-del-sol" or simply "barcelona") so I'm wondering how I can deal with this variable number of elements in the URL? The constant will be that after the region name, there will be 2 words, the number of bedrooms and the word "bedroom" or "bedrooms". Would it be possible to work backwards from the end of the string and parse the data that way rather than having a rigid template? Alternatively, my other thought would be to simply pass the entire filename as 1 variable to a PHP page and then parse it in PHP, so for example pass this: "path/to/file/page.php?old_filename=costa_blanca_1_bedroom.html" Is this a good idea? Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/206665-a-tricky-rewrite-situation/#findComment-1080981 Share on other sites More sharing options...
premiso Posted July 4, 2010 Share Posted July 4, 2010 Yea, that would only require one rewrite and if all files are under a certain folder, or they are the only ".html's" on the site, that would be easier: RewriteRule ^path/(.*)\.html$ path/to/file.php?old_file=$1 [L] Should do what you wanted. Quote Link to comment https://forums.phpfreaks.com/topic/206665-a-tricky-rewrite-situation/#findComment-1080995 Share on other sites More sharing options...
adambedford Posted July 7, 2010 Author Share Posted July 7, 2010 Thank you, that looks like the perfect solution! Quote Link to comment https://forums.phpfreaks.com/topic/206665-a-tricky-rewrite-situation/#findComment-1082376 Share on other sites More sharing options...
adambedford Posted July 7, 2010 Author Share Posted July 7, 2010 Having said that, I'm actually getting an error message using the following code: RewriteEngine on RewriteRule ^(.*)\.html$ url_rewrite.php?original_filename=$1 [L] The error message is: Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmaster@ and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/206665-a-tricky-rewrite-situation/#findComment-1082383 Share on other sites More sharing options...
premiso Posted July 7, 2010 Share Posted July 7, 2010 Does your server support mod_rewrite? If not you may have to enable it, if it does you have to allow access to it via the vhosts / httpd configuration file under the <Directory /path/to/your/site/> AllowOverride All Here is an article to help out with figuring out if that is the culprit: http://www.debian-administration.org/articles/136 Quote Link to comment https://forums.phpfreaks.com/topic/206665-a-tricky-rewrite-situation/#findComment-1082414 Share on other sites More sharing options...
adambedford Posted July 7, 2010 Author Share Posted July 7, 2010 I'm using shared hosting so I don't get too much access to the server. I have checked, however, and they say that the mod_reqrite module is enabled. Any ideas why this is still not working? :S Quote Link to comment https://forums.phpfreaks.com/topic/206665-a-tricky-rewrite-situation/#findComment-1082448 Share on other sites More sharing options...
cags Posted July 7, 2010 Share Posted July 7, 2010 Does a simple rewrite also break your site? RewriteEngine On RewriteRule ^.*$ http://www.google.com [R=302] Quote Link to comment https://forums.phpfreaks.com/topic/206665-a-tricky-rewrite-situation/#findComment-1082689 Share on other sites More sharing options...
adambedford Posted July 7, 2010 Author Share Posted July 7, 2010 Yeah it does, i get the same Internal Server Error message. I guess that means theres a problem with the server setup then? I've already contacted the hosting company and I'm awaiting a reply. Is there anything I can do in the meantime do you think? Unfortunately, I don't have access to any of the server config stuff because it's shared hosting. Quote Link to comment https://forums.phpfreaks.com/topic/206665-a-tricky-rewrite-situation/#findComment-1082710 Share on other sites More sharing options...
cags Posted July 8, 2010 Share Posted July 8, 2010 If you don't have access to any of the config then there is likely nothing you can do. Have you tried the basic rewrite in an IfModule block? If that works then the answer is almost certainly that mod_rewrite isn't enabled. <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^.*$ http://www.google.com [R=302] </IfModule> Quote Link to comment https://forums.phpfreaks.com/topic/206665-a-tricky-rewrite-situation/#findComment-1082939 Share on other sites More sharing options...
adambedford Posted July 8, 2010 Author Share Posted July 8, 2010 Thanks for your suggestions! That returns the same server error...which most likely means that mod_rewrite IS enabled, but theres something wrong with it, right? Quote Link to comment https://forums.phpfreaks.com/topic/206665-a-tricky-rewrite-situation/#findComment-1083082 Share on other sites More sharing options...
cags Posted July 8, 2010 Share Posted July 8, 2010 That would indeed seem to be indicated. If that is literally all that's in your .htaccess then mod_rewrite must be enabled, because if it isn't Apache will be treating it like an empty file because it won't go into the 'if block'. Normally internal server errors will cause an error to be written to an error log, but chances are if you are on shared hosting, you won't actually have access to view those logs. The only other thing I can think of is if you perhaps tried adding... Options +FollowSymLinks ... at the top of your .htacess file. Quote Link to comment https://forums.phpfreaks.com/topic/206665-a-tricky-rewrite-situation/#findComment-1083106 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.