Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
May 25, 2012, 12:44:44 PM

Pages: [1]   Go Down
  Print  
Author Topic: rewriting file pathes from SEO friendly URLs  (Read 941 times)
pandaspray
Newbie
*
Offline Offline

Posts: 3


« on: August 08, 2011, 04:40:59 PM »

How would one rewrite apache code to insert a directory when looking for a folder on a web server?

At the moment the url is:
public_html//files/images/pic1.jpg

I need the path to be:
public_html/cms/files/images/pic1.jpg

Quite specifically it must add this detail when retrieving files from the content managment system.

This is a necessary step when installing drupal in a sub directory of the root server. The other step for .htaccess is here:
http://drupal.org/node/1162166

Within Drupal it is:
http://drupal.org/comment/reply/1233622/4814142

I imagine the change must be in the .htaccess of the root directory.
Logged
MrPhil
Senior Moderator
Berserker Poster
*****
Offline Offline

Posts: 5220



« Reply #1 on: August 09, 2011, 04:51:57 AM »

So you want a Drupal-produced address of /files/images/* to map to a real address of /cms/files/images/*? Easy.
Code:
RewriteEngine On
RewriteCond  %{REQUEST_URI}  ^/files/images/  [NC]
RewriteRule  ^(.*)$  /cms/$1

Does the URL really have a double // in it? That's wrong. You've got an extra / either at the end of /home/ACCOUNT/public_html or at the beginning of files/images/... Fix your configuration before doing anything else.

If you have installed Drupal in a subdirectory, I can't believe that you can't specify somewhere the actual base path ("cms") and not have to go through this .htaccess business. What else in Drupal is going to have to be manually redirected this way? There is a configuration file somewhere (I don't recall the name) where you specify the actual path. I don't think you set up your configuration correctly.
Logged

Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-
pandaspray
Newbie
*
Offline Offline

Posts: 3


« Reply #2 on: August 12, 2011, 08:42:59 AM »

Code:
# Use PHP5 as default
AddHandler application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml

suPHP_ConfigPath /home/n000re2/public_html

# Use PHP5 as default
AddHandler application/x-httpd-php5 .php

# lunarpages.com
# .htaccess primary domain to subfolder redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.

# Do not change this line.

RewriteEngine on

# Change yourdomain.com to be your primary domain.

RewriteCond %{HTTP_HOST} ^(www.)?cms.com$

# Change 'subfolder' to be the folder you will use for your primary domain.

RewriteCond %{REQUEST_URI} !^/cms/

# Don't change this line.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Change 'subfolder' to be the folder you will use for your primary domain.

RewriteRule ^(.*)$ /cms/$1

# Change yourdomain.com to be your primary domain again.
# Change 'subfolder' to be the folder you will use for your primary domain
# followed by / then the main file for your site, index.php, index.html, etc.

RewriteCond %{HTTP_HOST} ^(www.)?cms.com$
RewriteRule ^(/)?$ cms/index.php [L]

This is the current .htaccess file. I thought it would not be important, but it appears so... I am using a module called domain access that allows me to run several domains from one installation. On further testing this code I can't get any pictures to work., and it maybe due to errors in the amendments I made to .htaccess. You seem to have spotted something obivous that eludes me still as I look at the code.

When I try to upload an image it comes up with:

Code:
An AJAX HTTP request terminated abnormally.
Debugging information follows.
Path: /file/ajax/field_wp_blog_img/und/0/form-GBwpOVmKTsnu6B6L4yS2qTap8FgiOCAU7pDt4Lnz8Do
StatusText: n/a
ResponseText: [{"command":"settings","settings":{"basePath":"\/","pathPrefix":"","ajaxPageState":{"theme":"rubik","theme_token":"zLWOnY7LsBQQxcRNlhS6QpRZi4z-TX6QKcvevlqSuM8","css":{"modules\/overlay\/overlay-parent.css":1},"js":{"sites\/all\/libraries\/headjs\/head.min.js":1,"headjs--head":1,"headjs--settings":1}},"overlay":{"paths":{"admin":"node\/*\/webform\nnode\/*\/webform\/*\nnode\/*\/webform-results\nnode\/*\/webform-results\/*\nnode\/*\/submission\/*\nnode\/*\/edit\nnode\/*\/delete\nnode\/*\/revisions\nnode\/*\/revisions\/*\/revert\nnode\/*\/revisions\/*\/delete\nnode\/add\nnode\/add\/*\noverlay\/dismiss-message\nuser\/*\/shortcuts\nadmin\nadmin\/*\nbatch\ntaxonomy\/term\/*\/edit\nnode\/*\/translate\nuser\/*\/cancel\nuser\/*\/edit\nuser\/*\/edit\/*","non_admin":"admin\/structure\/block\/demo\/*\nadmin\/reports\/status\/php"},"ajaxCallback":"overlay-ajax"},"admin_menu":{"destination":"destination=file\/ajax\/field_wp_blog_img\/und\/0\/form-GBwpOVmKTsnu6B6L4yS2qTap8FgiOCAU7pDt4Lnz8Do","replacements":{".admin-menu-users a":"1 \/ 0"},"margin_top":1,"position_fixed":1,"tweak_tabs":1,"toolbar":[]},"clientsideValidation":{"general":{"errorClass":"error","wrapper":"li","validateTabs":1},"forms":{"wp-blog-node-form":{"settings":{"errorContainer":"#formerrors-wp-blog-node-form","errorLabelContainer":"#formerrors-wp-blog-node-form ul"},"rules":{"title":{"required":true,"messages":{"required":"Title field is required.","maxlength":"Title field has to have maximum 128 values."},"maxlength":128},"name":{"maxlength":60,"messages":{"maxlength":"Authored by field has to have maximum 60 values."}},"date":{"maxlength":25,"messages":{"maxlength":"Authored on field has to have maximum 25 values."}},"taxonomy_wp_blog_tags[und]":{"maxlength":1024,"messages":{"maxlength":"Blog tags field has to have maximum 1024 values."}},"field_wp_blog_img[und][0][alt]":{"maxlength":80,"messages":{"maxlength":"Alternate text field has to have maximum 80 values."}},"field_wp_blog_img[und][0][title]":{"maxlength":500,"messages":{"maxlength":"Title field has to have maximum 500 values."}},"path[alias]":{"maxlength":255,"messages":{"maxlength":"URL alias field has to have maximum 255 values."}},"menu[link_title]":{"maxlength":128,"messages":{"maxlength":"Menu link title field has to have maximum 128 values."}}},"checkboxrules":{"domains":{"checkboxgroupminmax":[1,99,"#edit-domains"],"messages":{"checkboxgroupminmax":"Publish to field is required."}}}}}},"ajax":{"edit-field-wp-blog-img-und-0-remove-button":{"wrapper":"edit-field-wp-blog-img-und-0-ajax-wrapper","effect":"none","progress":{"type":"throbber","message":null},"event":"mousedown","keypress":true,"prevent":"click","url":"\/file\/ajax\/field_wp_blog_img\/und\/0\/form-GBwpOVmKTsnu6B6L4yS2qTap8FgiOCAU7pDt4Lnz8Do","submit":{"_triggering_element_name":"field_wp_blog_img_und_0_remove_button","_triggering_element_value":"Remove"}}}},"merge":true},{"command":"insert","method":"prepend","selector":"head","data":"\u003cstyle type=\"text\/css\" media=\"all\"\u003e@import url(\"http:\/\/lotuspuresound.net\/modules\/overlay\/overlay-parent.css?lpt9iz\");\u003c\/style\u003e\n","settings":null},{"command":"insert","method":"prepend","selector":"head","data":"\u003cscript type=\"text\/javascript\" src=\"http:\/\/lotuspuresound.net\/sites\/all\/libraries\/headjs\/head.min.js?v=0.96\"\u003e\u003c\/script\u003e\n\u003cscript type=\"text\/javascript\"\u003e\n\u003c!--\/\/--\u003e\u003c![CDATA[\/\/\u003e\u003c!--\nhead.js(\"http:\/\/lotuspuresound.net\/misc\/jquery.js\", \"http:\/\/lotuspuresound.net\/misc\/jquery.once.js\", \"http:\/\/lotuspuresound.net\/misc\/drupal.js\", \"http:\/\/lotuspuresound.net\/misc\/ui\/jquery.ui.core.min.js\", \"http:\/\/lotuspuresound.net\/misc\/jquery.ba-bbq.js\", \"http:\/\/lotuspuresound.net\/modules\/overlay\/overlay-parent.js\", \"http:\/\/lotuspuresound.net\/misc\/jquery.cookie.js\", \"http:\/\/lotuspuresound.net\/misc\/jquery.form.js\", \"http:\/\/lotuspuresound.net\/misc\/ajax.js\", \"http:\/\/lotuspuresound.net\/sites\/all\/modules\/admin_menu\/admin_devel\/admin_devel.js\", \"http:\/\/lotuspuresound.net\/sites\/all\/modules\/mollom\/mollom.js\", \"http:\/\/lotuspuresound.net\/sites\/all\/modules\/panels\/js\/panels.js\", \"http:\/\/lotuspuresound.net\/sites\/all\/modules\/admin_menu\/admin_menu.js\", \"http:\/\/lotuspuresound.net\/sites\/all\/modules\/admin_menu\/admin_menu_toolbar\/admin_menu_toolbar.js\", \"http:\/\/lotuspuresound.net\/sites\/all\/modules\/clientside_validation\/jquery-validate\/jquery.validate.js\", \"http:\/\/lotuspuresound.net\/sites\/all\/modules\/clientside_validation\/clientside_validation.js\", \"http:\/\/lotuspuresound.net\/misc\/progress.js\", \"http:\/\/lotuspuresound.net\/modules\/file\/file.js\", \"http:\/\/lotuspuresound.net\/sites\/all\/themes\/rubik\/js\/rubik.js\", \"http:\/\/lotuspuresound.net\/sites\/all\/modules\/views\/js\/jquery.ui.dialog.patch.js\");\n\/\/--\u003e\u003c!]]\u003e\n\u003c\/script\u003e\n\u003cscript type=\"text\/javascript\" defer=\"defer\"\u003e\n\u003c!--\/\/--\u003e\u003c![CDATA[\/\/\u003e\u003c!--\nhead.ready(function(){jQuery.extend(Drupal.settings, {\"basePath\":\"\\\/\",\"pathPrefix\":\"\",\"ajaxPageState\":{\"theme\":\"rubik\",\"theme_token\":\"zLWOnY7LsBQQxcRNlhS6QpRZi4z-TX6QKcvevlqSuM8\",\"js\":{\"misc\\\/jquery.js\":1,\"misc\\\/jquery.once.js\":1,\"misc\\\/drupal.js\":1,\"misc\\\/ui\\\/jquery.ui.core.min.js\":1,\"misc\\\/jquery.ba-bbq.js\":1,\"modules\\\/overlay\\\/overlay-parent.js\":1,\"misc\\\/jquery.cookie.js\":1,\"misc\\\/jquery.form.js\":1,\"misc\\\/ajax.js\":1,\"sites\\\/all\\\/modules\\\/admin_menu\\\/admin_devel\\\/admin_devel.js\":1,\"sites\\\/all\\\/modules\\\/mollom\\\/mollom.js\":1,\"sites\\\/all\\\/modules\\\/panels\\\/js\\\/panels.js\":1,\"sites\\\/all\\\/modules\\\/admin_menu\\\/admin_menu.js\":1,\"sites\\\/all\\\/modules\\\/admin_menu\\\/admin_menu_toolbar\\\/admin_menu_toolbar.js\":1,\"sites\\\/all\\\/modules\\\/clientside_validation\\\/jquery-validate\\\/jquery.validate.js\":1,\"sites\\\/all\\\/modules\\\/clientside_validation\\\/clientside_validation.js\":1,\"misc\\\/progress.js\":1,\"modules\\\/file\\\/file.js\":1,\"sites\\\/all\\\/themes\\\/rubik\\\/js\\\/rubik.js\":1,\"sites\\\/all\\\/modules\\\/views\\\/js\\\/jquery.ui.dialog.patch.js\":1}},\"overlay\":{\"paths\":{\"admin\":\"node\\\/*\\\/webform\\nnode\\\/*\\\/webform\\\/*\\nnode\\\/*\\\/webform-results\\nn
ReadyState: undefined

The address is 3000realms.com. It might just make it easier to see the problem.
The Lunarpages account was setup on the 3000realms.com domain. It is the only domain which is exhibiting the necessity for the subdirectory in pathes. I believe it maybe setup like that because it is the parent domain for my account. Ive moved it from being the primary domain in the installation but the subdirectory presence was persistent. I only have pieces of the puzzle which might not be complete for the full system to be operational even though they  currently seem to be doing part of the whole task. I Would really like to proceed with development and design to get more clients in.
Logged
MrPhil
Senior Moderator
Berserker Poster
*****
Offline Offline

Posts: 5220



« Reply #3 on: August 14, 2011, 03:36:07 PM »

I'm not sure I understand where you're trying to get to, but here's what your current .htaccess is doing:
Code:
# Use PHP5 as default
AddHandler application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
>>>>>>>>>>>>> use  PHP 5. this may now be unnecessary if your default server setup is to use PHP 5

suPHP_ConfigPath /home/n000re2/public_html
>>>>>>>>>>>>> tell PHP where to find "php.ini"

# Use PHP5 as default
AddHandler application/x-httpd-php5 .php
>>>>>>>>>>>>> DUPLICATE, get rid of it

# lunarpages.com
# .htaccess primary domain to subfolder redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.

# Do not change this line.

RewriteEngine on

# Change yourdomain.com to be your primary domain.

RewriteCond %{HTTP_HOST} ^(www.)?cms.com$
>>>>>>>>>>>>> periods are special characters. escape them:  ^(www\.)?cms\.com$
>>>>>>>>>>>>> IF the domain is cms.com or www.cms.com ...

# Change 'subfolder' to be the folder you will use for your primary domain.

RewriteCond %{REQUEST_URI} !^/cms/
>>>>>>>>>>>>> AND the requested URI file path does NOT already begin with "/cms/" ...

# Don't change this line.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
>>>>>>>>>>>>> AND the requested path/file does NOT exist ...

# Change 'subfolder' to be the folder you will use for your primary domain.

RewriteRule ^(.*)$ /cms/$1
>>>>>>>>>>>>>  stick  /cms/ in front of whatever was given. rewrite the URL.

# Change yourdomain.com to be your primary domain again.
# Change 'subfolder' to be the folder you will use for your primary domain
# followed by / then the main file for your site, index.php, index.html, etc.

RewriteCond %{HTTP_HOST} ^(www.)?cms.com$
RewriteRule ^(/)?$ cms/index.php [L]
>>>>>>>>>>>>> IF cms.com or www.cms.com (remember to escape the . ) ...
>>>>>>>>>>>>> IF it's bare (just / at most), go to cms/index.php

I see several minor (?) problems here.
1. You have the PHP 5 selection code twice. Neither may be needed, but you can get rid of the second one anyway.
2. All of this stuff applies only to [www.]cms.com, and not to any other domains. Is that your intent? Are your other domains parked, add-on, or subdomains?
3. Adding /cms/ in front of any existing URI appears to be duplicated. You do it if the URI doesn't start with /cms/ (and the file or directory requested doesn't exist), and you do it again if it's a bare domain name (just http://[www.]cms.com or http://[www.]cms.com/ ). It may be harmless, as I think the previous rewrite will change / to /cms/, which should pick up index.php anyway.

How did you "move it from being the primary domain in the installation"? Did LP do it for you, or did you do something with URL rewriting? Maybe it would be easiest if you told us what the setup was that worked before you started changing things, and what you're trying to do and exactly you did to change things. You mention "but the subdirectory presence was persistent" -- that sounds like maybe you're not giving the full story here. Of course, Drupal will have a given directory setup "frozen" into its configuration settings -- did you ever change them?

If you set up Drupal with a given directory setup, you need to find the configuration file(s) and look through them to see if the old setup is in there and needs to be modified. I would not attempt to patch up the system by redirecting/rewriting certain server requests -- I would get it configured correctly in the first place, even if that means wiping out your installation and reinstalling it, with the old database contents restored. I don't think that the database contains any path-sensitive information, just the configuration file(s) do, so that should be safe (back up files and database first, so you can at least get back to the current state if all else fails).

There is a Drupal support community at drupal.org, which presumably you are aware of.
Logged

Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-
pandaspray
Newbie
*
Offline Offline

Posts: 3


« Reply #4 on: August 16, 2011, 09:27:17 AM »

Thank you.

I'll explain the setup more.

Drupal usually runs with one one domain out of the box. I used a module called Domain Access that allowed the use of several domains or subdomains.

Using this module requires that no changes are made to the settings.php file regarding base name url. However it was unable to remedy the subdirectory installation. I was later informed that subdirectory information is not kept by drupal. I went through the backend database and believe this to be true as I removed any instances of the subdirectory and the system still persisted in showing the subdirectory.

The idea then arose to use Domain Access to change the primary domain to a subdomain of the orginal primary and have the primary setup anew. So I create the domain dev.3000realms.com and swap it with 3000realms.com as being the primary domain FOR DRUPAL. I do not think this changes the primary domain on my account with Lunarpages, the domain through which I opened my account with. After swapping, I delete 3000realms.com from the installation. I recreate it and it manifests the same subdirectory path requirement for files and admin navigation. It  needs to work seamlessly if its to work at all in the long run.

This brought me to the belief of a hard coded setting in the apache installation which I don't have access too, but could perhaps address through .htaccess and mod rewrite.

Only cms.com need rewriting as its the only domain exhibiting the subdirectory. The others don't and I imagine that is so because they are not the primary domain setup with Lunarpages. I am guessing, as I'm not aware of Lunarpages setup for managing domains except through a control panel, and this does not say how it relates to the account's primary domain.

I can see potentially how my account's primary domain is the home for the other domains and has special set settings while the others can remain flexible. I cannot say for sure.

In brief the URL needs to show cms.com/news
not cms.com/cms/news
for just cms.com
not cms2.com or cms4.com or dev.cms.com because they work fine.

After the Apache URL rewrite has been enabled, it seems, file locations need to be correctly routed with the subdirectory as pages are not being found. Usually this Apache rewrite needs a setting settings.php.

This is drupal code in settings.php compensating for the many domains with the apache rewrite code.

Code:
<?php
include DRUPAL_ROOT '/sites/all/modules/domain/settings.inc';

global 
$base_url$base_path$base_root;
// These three variables will be set, relative to the current page request,

// Modify the base globals so all links ignore the directory.
// In your case, this likely has to be conditional (i.e., HTTP_HOST != 'dev').
$base_url $base_root;
$base_path '/';
?>

I did not seem to need to create a conditional for the dev subdomain.
Logged
MrPhil
Senior Moderator
Berserker Poster
*****
Offline Offline

Posts: 5220



« Reply #5 on: August 16, 2011, 07:35:24 PM »

Hmm. I think you're getting deeper into this than I'm comfortable trying to offer advice. As you know about drupal.org, I'll guess that you've given a try to asking there. I have this feeling that you're making a very complicated mountain out of a molehill, but I don't want to lead you astray in case you really are in a place beyond my limited Drupal knowledge. If I think of anything further I'll try to remember to mention it. Good luck!
Logged

Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-
cancy12
Space Explorer
***
Offline Offline

Posts: 6


« Reply #6 on: August 25, 2011, 12:02:53 AM »

Using this module requires that no changes are made to the settings.In brief the URL needs to show cms.com/news. You should find out clearly.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: