how do i hide /magento/ in my site's url? - php

A site has an existing system (lets call it mysite)
and the client asks to put in magento.
My directory structure goes something like this:
ROOT
-index.php (this is the app's main controller)
-.htaccess
/blog (runs wordpress)
/assets (current system's media folder)
/magento (this is where all magento files go)
Problem is if I set up magento and specify in the installation that base URL is http://example.com, magento loads up mysite.
Leaves me no choice but to setup magento with base URL set to http://example.com/magento/ and it runs perfectly.
However the client wants me to feel hell and asks me to hide magento in the URL.
I’m not really versed in .htaccess and I know only simple rewrite codes so I tried forwarding any HTTP requests that start with /magento to the magento folder and came up with:
RewriteCond %{REQUEST_URI} !^/magento(.*)
RewriteRule (.*) /magento/$1 [L]
Just when I thought it was working, mysite links all became unaccessible and forwards to the magento system displaying it's 404 page.
So, uhm, can I ask for help how to construct the .htaccess to hide the /magento/ on the URLs without affecting the current system aka mysite?

Because you have existing applications off the webroot, you cannot get away with using nothing instead:
### webroot/.htaccess
RewriteRule ^whatiwanttouseinsteadofmagento/(.*)$ magento/$1 [L]

From how I see the problem you will not be able to hide magento completely and use your site as well in the same time.
If you want Magento in the root of the public folder you should just point the virtualHost to your magento installation but this will let your blog and your main controller out of the public view. This is more or less the same with what you did by redirecting all calls in the .htaccess to magento folder.
What I suggest is to change the magento name to something more anonymous like "shopping" or "cart", and remember that a folder rename is preferable to a .htaccess file in terms of security and performance.

Let's look at it:
RewriteCond %{REQUEST_URI} !^/magento(.*)
So we're saying the condition is anything that is not /magento(.*), so everything but that directory? This would redirect everything, including your blog, assets, and any other directories.
Without specifying each and every file that needs to be redirected to the magento directory, there really is no easy way of doing it. I suppose you could redirect any file that does not contain a "/" in it and ends with the extension .php to the magento directory. That way only files in the root web directory will redirect to magento, but if you used other directories inside the magento directory you'd still need to add separate rules for them.

this answer comes very late but I guess you wanted something like
RewriteCond %{REQUEST_URI} !^/(blog|assets|magento)(.*)$
RewriteRule ^(.*)$ /magento$1 [L]

Related

.HTACCESS RewriteRule not working as expected

I have a magento website, that is currently operating. Within a subfolder of this site, I have placed a 3rd party application that also has its own HTACCESS file to handle routing for its application.
When I access the folder http://example.com/somefolder the screen I expect shows up, but when I navigate to http://example.com/somefolder/newroute, I instead land on a magento 404 screen.
I have traced this to the magento htaccess file, in all cases, unlesss the path physically exists the rewriterule will always send the request to the index.php - this explains why Im getting there.
To fix this issue, I wrote a little rewriterule which I placed in the htaccess file of the magento store. The goal was to add an exception to any request that came through and contained any reference to my subfolder. The thought is now it should hit the path its supposed, then hit the htaccess file, and then route me to where IM supposed to be in this other application. Unfortunately it doesnt seem to work, after adding the rule I end up the same place - magento.
Here is what I've written:
RewriteRule ^(.*somefolder.*)$ $1 [L]
Im not sure what could be going wrong, as I think the approach seems pretty straight forward. Any ideas on how to remedy this situation?
Thanks.
Here is Your Simple Answer.Also Used By me on my site.
RewriteCond %{REQUEST_URI} !^/(yourfoldernameHERE)$

htaccess redirect to subfolders resources

I have a problem:
I have to modify an application written in Zend 1 that was deployed to the domain root. now to test it the customer gave me a root subfolder called [domain]/social
When I run it, I have a lot of problem because all paths are like "/resource", but in this case the fiddler show me that the request look for [domain]/resource ad not for [domain]/social/resource.
It happens with script sources, ajax urls, hrefs...all!
Is there a way to fix the problem?
I am not quite familiar with Zend, but is there a main config file that sets the application root folder? (Like joomla) You can modify that if it exists.
Other option would be to preg_match or str_replace all instances of the domain name in the code ( like when moving a Worpress site) but you should definately do that with a sample content not couple hundred pages).
And here is a htaccess snippet as well:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/social/$1 [R=301,L]
Be sure to put the htaccess under the development folder not under the root, oterwise you're facing issues.
I suggest cheking for a config file first. Hope one of this helps!

Redirect directory to subdomain cpanel

Alright I have already contacted BlueHost Support and they couldn't figure out how to fix this issue. I've also tried to use cpanels 301 permanent redirect but that doesn't work so I decided to give it a whirl on here.
I host with BlueHost.com if you haven't caught that by now. The file structure is as follows:
public_html/
directory1/subdomaindirectory
directory2
directory3
I have my main website in my root (public_html). Then I have to create new directories and assign the url to that directory. So essentially if you typed in www.maindomain.com/directory1 it would show the website in the directory. I would like to modify the .htaccess to redirect that to it's original domain so www.maindomain.com/directory1 would go to www.directory1.com
The same for subdomains. I created subdomain.directory1.com and pointed it to public_html/directory1/subdomaindirectory and if you go to www.directory1.com/subdomain it pulls up the site.
I realize theoretically it's the same thing but it bugs me that you are able to pull up a website like that.
Is there anyway to modify the .htaccess to fix this issue?
In.htaccess you could do it like this
RewriteEngine On
RewriteBase /gorbox
RewriteCond %{HTTP_HOST} ^www.gorbox.com$ [NC]
RewriteRule ^support$ http://support.gorbox.com [L,R=301]
Put this in the .htaccess file that resides within the root folder of www.gorbox.com

Accessing CodeIgniter app from sibling subdirectory

I'm having a scenario where I had to deploy multiple directories for different languages. Development has initially centered on one of those languages, and just one part of the whole site is a small CI app.
I'm trying to avoid copying the whole app for the several other languages, and redirecting to it with an .htacces. The latter is working fine, but CI returns a 404 error when accessed from a URL different to the real one.
My best guess is that certain configuration files must exist with unique properties that configure the additional root URLs, but I don't know where to start (and Google didn't come up with a similar scenario).
File Structure:
public_html/
lang1/
app/
(the actual CI app)
other static stuff...
lang2/
app/
.htaccess (redirecting to /lang1/app/)
other static stuff...
lang3/
...
Additional info:
The $config['base_url'] is set to http://.../lang1/app/.
The .htaccess:
RewriteEngine on
RewriteRule ^(.*)$ /lang1/app/$1 [L]
I was able to accomplish this by my own. For those who might find this question in the future, these are the steps to access your application from a different directory. Considering the scenario introduced in the question above, the following example will work for the deployment of of a ghost version of the app in the lang2 directory:
1.- Copy only the index.php file from the root of your CI installation (from lang1/app/index.php) to the lang2/app/ directory.
2.- Edit the following lines:
$system_path = '../../lang1/app/system';
$application_folder = '../../lang1/app/application';
//Even if the documentation suggests the necessity of a _full path_,
//this works perfectly well for 2.1.0
3.- Add any configuration you may want to have set explicitly for said subdirectory, these will be set to $this->config, replacing the values set in the config file in your base application:
$assign_to_config['lang_version'] = 'lang2';
4.- You have to set a proper base_url. In this case, we could reuse the lang_version config we just included. This way, we can forget about this line in the next languages we need to create.
$assign_to_config['base_url'] =
'http://www.example.com/' . $assign_to_config['lang_version'] . '/app/';
5.- Create an .htaccess file inside lang2/app to make sure that any static assets (js, css, images) accessed by the HTML are get from the actual assets folder inside the original app directory, like in lang1/app/assets:
RewriteEngine on
RewriteRule ^assets/(.*)$ /lang1/app/assets/$1 [L]
6.- Add to this .htaccess your usual rule to keep your URLs friendly, but this time directing all traffic to the ghost copy of your app:
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ /lang2/app/index.php/$1 [L]
7.- Grab a beer or any other beverage you drink to celebrate success, always respecting your local laws. Profit. Your controllers will have to read the config('lang_version') value to present the content in the proper language to the user. You may use the included language helper for that, or any other solution you prefer.
Why would you do this? Theres a thing called i18n.
http://codeigniter.com/wiki/CodeIgniter_2.1_internationalization_i18n/
Why not use this? Didnt copying the app folders seem a bit tedious to you? Theres a language helper for a reason.
I hope this helps.

.htaccess in subfolder

I install a new cms (phpmydirectory) in a subfolder. In the root there is a wordpress with friendly url's.
When I activate the friendly url's in phpmydirectory, I get an 404 error in the categories and locations, but no in the listings. The 404 error appear in the blog template and URL.
How fix the -htaccess so the subfolder read the .htaccess in the subfolder ando no the one in root?
Apache always reads all .htaccess files along the path to the root directory. This cannot be changed (except for disallowing use of .htaccess alltogether). The best you can get is making sure that rules for mod_rewrite in the parent directory do not apply. This might be possible using
RewriteRule ^(.*)$ $1 [L]
as the last rule in your phpmydirectory directory.
Do you have the subdirectory specified as the $BASE_URL in your defaults.php file for PMD? I'm operating with a similar setup right now, and did not have to make adjustments to the .htaccess file. However, its not competing with a Wordpress install in the root directory (its an older version of phpmydirectory instead), so that might be causing a different issue than my setup.

Categories