开发者

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

开发者 https://www.devze.com 2022-12-22 04:01 出处:网络
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:

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 displayi开发者_JAVA百科ng 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]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号