Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/206665-a-tricky-rewrite-situation/
Share on other sites

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.

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!

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.

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?

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

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.

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>

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.