I actually got an answer that if I want to change my url from www.mydomain.com/laravel4/public/posts into www.mydomain.com/posts
this is what I have to do with my .htaccess
RewriteEngine On
RewriteRule !^laravel4/public/ /laravel4/public%{REQUEST_URI} [L,NC]
but I have another question if I want the url to be www.mydomain.com/laravel4/posts which takes out the public what should I modify? I thought taking out the laravel4 in the code above would work but doesn't seem that easy :(
Ideally you should move the Laravel install out of the document root and just move the contents of the public folder into your document root and edit the index.php and bootstrap/paths.php accordingly, or alternatively set the document root to the public folder of Laravel, some hosts will change the document root for you if you open a support ticket.
However thats not always possible depending on your host, and most people will tell you to go off and find a better host, but again, thats not always an option.
Below is a .htaccess example you can use to rewrite all URLs to the public/index.php of Laravel, but be warned, this isn't a very secure way to setup Laravel, and anyone could potentially access any of your configuration and other files that exist in your document root, exposing your database passwords and secret keys used to encryption.
RewriteEngine On
RewriteRule ^ laravel4/public/index.php [L]
Updated as per request
RewriteEngineOn
RewriteRule ^laravel4/.* laravel4/public/index.php [L]
You can use this rule:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/laravel4/public(/|$) [NC]
RewriteRule ^laravel4/(.*)$ /laravel4/public/$1 [L,NC]
Related
I have a site called www.example.com and I have my php files in it. I store all my working files in www.example.com/site. I want to view the site in www.example.com instead, without moving my site content. What can I do?
This is currently what I am typing in .htaccess. It will redirect my site to www.example.com/site but I think the url is ugly
RewriteEngine on
RewriteBase /
RewriteRule ^(/.*|)$ /magento$1 [NC,L]
Let me see if i understood this correctly.
You have a domanin, www.example.com, and on this domain you want to display the content of a directory, www.example.com/site !?
If this is the case then you need to change the document root
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} !^/site
RewriteRule ^(.*)$ /site/$1 [L]
or
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ /site/$1 [L,NC]
There are 2 things you must consider :
If I understand your request, you are accessing some PHP files using www.example.com, but what you want is to access www.example.com/site, but without the /site, right ?
So basicaly, what you're looking for is NOT rewrite, it's just pointing your domain to the good folder, which is /site, right ?
If you're using Apache2, you have to edit your apache's configuration file in /etc/apache2/site-available/default (or remplace default with the name of the virtualhost you may have created).
In this file, look for the directive DocumentRoot. It should lead to the "root" directory of your pages (the one you access typing www.example.com)
I think you just have to append /site to this DocumentRoot and then reload your apache2 with service apache2 reload
You're website www.example.com will now lead to the correct directory.
If it's still not working, you must consider looking into magento's admin, because magento is rewriting url according to the Base URL you specify inside Admin / Configuration / general / web.
You'll have to modify Base_URL in both Secure and Un-Secure sections.
Then it should work fine.
I would comment out the Rewrite bloc you're using at the moment, or maybe I didn't fully undestand what you want to achieve.
I know there are TONS of questions on this website regarding this topic, as well as TONS of tutorials around google. However I have searched for a while now and I cannot seem to find one that explains my specific situation.
I am building a social application in which the whole application is being stored in a directory of a subdomain the website like so: subdomain.example.com/network/ <-- network being the directory of all the application files.
I have my .htaccess file located in the root of the subdomain and as of right now I have it removing .php from all the files and that is working throughout the entire project as it should. I have a user.php page which each user's profile is based off and the unique identifier for each user is their username (not 'id' like most people use.) So right now the urls look like /network/user.php?username=TylerB which is not very pretty. I have tried many different things to get this to look like /network/user/TylerB but nothing I try seems to work. I don't know if it's because it's in a directory, a subdomain or what. As of right now, when I have /network/user/TylerB (TylerB is my username) it gives me a 404 error.
Here is my current .htaccess file:
RewriteEngine On
RewriteRule ^user/([^/\.]+)/?$ user.php?username=$1 [L]
RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [L]
I would recommend setting the RewriteBase directive and matching on the full pattern, making sure to rewrite to the /network/ directory.
RewriteEngine On
RewriteBase /
RewriteRule ^network/user/([^/\.]+)/? /network/user.php?username=$1 [L]
RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [L]
Using the testing tool at http://htaccess.madewithlove.be/ I get an output of:
This rule was met, the new url is http://example.com/network/user.php?username=name
The tests are stopped because the L in your RewriteRule options
Alright, so I've downloaded a CMS for a server I'm setting up and I have some difficulty with the path the files are on.
I have put the CMS in a subdirectory on my server as the root directory is already being used by another CMS. However, the CMS repeatedly uses "/" in the code to link to their files. For example, an image is found using this code:
<img src="/images/banner.png" />
As you know this will not work, because the link above redirects the request to the images folder in the root of the server, not the subdirectory. The CMS also came with a ".htaccess" file, so I immediately thought that I could redirect all requests made using the "/" character to the subdirectory on the server. This is the original ".htaccess" file:
RewriteEngine On
RewriteRule ^index.php(|/)$ content/.php
RewriteRule ^error.php(|/)$ content/error.php
RewriteRule ^housekeeping(|/)$ housekeeping/index.php
RewriteRule ^(|/)$ content/$1.php
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ content/$1.php
RewriteRule ^rd/([^/]+)(|/)$ /rd.php?id=$1
RewriteRule ^quickregister/start(|/)$ /register/start.php
RewriteRule ^quickregister/step2(|/)$ /register/step2.php
RewriteRule ^quickregister/step3(|/)$ /register/complete.php
RewriteRule ^community/online(|/)$ content/online.php
RewriteRule ^community/vip(|/)$ content/vip.php
RewriteRule ^credits/goldvip(|/)$ content/goldvip.php
RewriteRule ^home/(..*)$ content/home.php?u=$1
RewriteRule ^articles/(..*)$ content/articles.php?story=$1
ErrorDocument 403 /content/error.php
ErrorDocument 404 /content/error.php
I thought that by adding
RewriteRule ^/$ /subdirectory/
the requests to "/" would be redirected, but to no avail. I have checked the apache configuration and it seems that overwriting the config using htaccess files is enabled, so if anyone is able to help me out I'd be very happy.
Thanks in advance!
EDIT:
I came real close to a solution. I inserted this code just below "RewriteEngine on":
RewriteRule ^(.*)/(.*)$ /private_servers/strebbohotel/$2
This returned the following error page when visiting the url "http://mysite.com/private_servers/strebbohotel/content/.php":
Not Found
The requested URL /private_servers/strebbohotel/.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
As you can see, it skips the "content" subdirectory for some reason. I believe it has something to do with the other lines of the .htaccess file but I can't figure out which ones. It also could be that I need a more complex regex, but I'm not particularly good with it so if someone could help me further I'd be thankful.
You have to change the .htaccess file on yout root directory - and that will mess with the other CMS. The only solution that comes to my mind is to use combination of RewriteCond's:
RewriteCond %{HTTP_REFERER} my_better_cms_url_regex
RewriteCond %{REQUEST_URI} ^/images/.*$
RewriteRule ^.*$ /subdirectory/%{REQUEST_URI}
That should do the trick. If you want to customize it, refer to this cheatsheet (or simmilar). But be aware, that .htaccess in root directory is checked against ALL requests made to your subdir cms - therefore the need for second condition.
The .htaccess file in your CMS subdirectory would have no effect on requests made against the server root directory. You would need to add an .htaccess there.
Even then though, I don't know how you would differentiate requests from the CMS (like the image request in your example) from those intended for the application in the web root.
Does your CMS not have any configuration setting that allow you to specify a path the the files other than the web root?
You want to use:
RewriteBase /another_root_dir/
in the beginning of your .htaccess file
I have looked at several examples of htaccess configs for websites within sub-directories, and tried most of them without 100% success.
My setup is:
using Yii framework
htaccess at public_html/.htaccess
site located inside public_html/mysite directory
index handling all requests located at public_html/mysite/frontend/www/index.php
The status of the URLs:
www.mysite.com works fine [ok]
www.mysite.com/controller/action shows me the homepage [wrong]
www.mysite.com/mysite/frontend/www/controller/action works fine [wrong, the item above should work instead]
My .htaccess at the moment looks like this:
AddHandler application/x-httpd-php53s .php .html
Options +SymLinksIfOwnerMatch
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !^/mysite/frontend/www
RewriteRule ^(.*)?$ /mysite/frontend/www/index.php [L]
I have tried everything, but I have no idea why www.mysite.com/controller/action won't work :(
Any help would be really appreciated! Thanks!
I found the answer to this similar question to be helpful. Here is how my rewrite rules ended up:
#Forward all non-existent files/directories to Yii
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) subdir/index.php/$1 [QSA,L]
This takes all non-existent files/folders and sends them to the yii script with initial url appended. QSA appends any query string that may be present in the initial url.
You didn't mention if you configured Yii's Url Manager for clean URLs. You need to, otherwise Yii expects the "route" to appear as a GET param named "r". If you didn't, consult this section of the definitive guide
You dont need to edit .htaccess. You just need to move the Yii entry script (index.php) and the default .htaccess up from the subdirectory to the webroot (so that they reside directly under public_html). Once you move index.php and .htaccess to the root directory, all web requests will be routed directly to index.php (rather than to the subdirectory), thus eliminating the /subdirectory part of the url.
After you move the files, you will need to edit index.php to update the references to the yii.php file (under the Yii framework directory) as well as the Yii config file (main.php). Lastly, you will need to move the assets directory to directly the webroot, since by default, Yii expects the assets directory to be located in the same location as the entry script).
That should be all you need to do, but if you need more details, I describe the approach fully here:
http://muhammadatt.tumblr.com/post/83149364519/modifying-a-yii-application-to-run-from-a-subdirectory
I also didn't update the .htaccess file, easier to modify the httpd.conf virtual host for the subdomain and change the DocumentRoot to point to your yii folder.
Thanks in advance.
I have redone my website with new folder structures
Old site structure:
www.domain.com/folder/file.aspx
New site structure:
www.domain.us/folder/file.php
Notice the new TLD. I have around 20 folders that I want to redirect. Is it possible to do this with one file or do I have to do a 301 for each individual folder from the old site to the new site? What is the best way to handle this?
Again,
Thanks in advance
You should use mod_rewrite for that. Put this in the .htaccess file in the public_html folder of your FTP:
RewriteEngine On
RewriteRule ^([^.]+)\.aspx$ $1.php [L]
This should make sure that when someone is calling Banana.aspx they get to see Banana.php.
The .htaccess file in the directory takes precedence over any .htaccess file in the parent directories. So, if you already have .htaccess file in each of your sub-directories then putting an .htaccess file in your root directory makes no sense.
Remove the .htaccess files from each of your sub-directories that you want to redirect and update the .htaccess file in your root folder. You probably need to put 20 rewrite rules like this. Keep in mind that removing .htaccecss from sub-directories will remove all restrictions that you [might] have put on that folder.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com
RewriteRule ^folder/file\.aspx$ http://domain.us/folder/file.php [R=301,NC,L]
RewriteRule ^folder2/file\.aspx$ http://domain.us/folder2/file.php [R=301,NC,L]
301 for permanent redirect, NC for No Case, L for Last rule to process if matches
OR
Update the .htaccess file in each directory that you want to redirect
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com
RewriteRule ^(.*)\.aspx$ http://domain.us/folder/$1.php [R=301,NC,L]
#the following might also do; just test it out
#RedirectPermanent (.*)\.aspx$ http://domain.us/folder/$1.php
So,, depending on your situation, you pick one. I'd go with option one so that all redirects are in one place. You can always move the restrictions from subdirectories' .htaccess to root's .htaccess.
If you use 301 PHP header() redirect, then I'm afraid it can only be done one-by-one.
But if you use mod_rewrite to handle this for you, then this is a relevant source for you to have a look: http://www.gnc-web-creations.com/301-redirect.htm