I installed Joomla 2.5 in /joomla/.
It's accessible by http://www.example.com/joomla/.
But I want it to be accessible when I browse http://www.example.com/ (or example.com, without www)
I thought configuration $live_site is because of this, but change it to http://www.example.com/, and it showed a blank page.
Should I edit root directory .htaccess? or Joomla .htaccess file ?
Redirecting non-www version to www
You can Redirect your domain from "non-WWW" to "WWW".
To redirect your domain to "WWW" you need to define a rule in your ".htaccess" file.
You can upload this file in the "root" directory of your site
For that you can set a rule as follows :
*******************************************
RewriteEngine on
RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]
********************************************
After defining the above rule in your ".htaccess" file When you type your domain in URL domainname.com it will get
redirected to WWW.
Related
Let's say i have installed laravel on a subfolder: i placed all the app stuff outside the html root, renamed the "public" directory in "laravel" and moved under the html root.
I can see the app by connecting to www.mydomain.com/laravel
I used the following .htaccess in the root html folder:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteCond %{REQUEST_URI} !^/laravel/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /laravel/$1
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteRule ^(/)?$ laravel/ [L]
Now i can access my site directly from www.mydomain.com
But i see that i can still access it from www.mydomain.com/laravel ... and since all the links are generated starting from the base url, the menu and every anchor href points to www.mydomain.com/laravel... even the canonical link of the pages contains "laravel".
Questions:
is there a way to avoid this??
should i worry for this?
Thanks for help.
If you are using apache, you need to configure your hosts. Either http-vhosts.conf or httpd.conf or similar file.
<VirtualHost >
...
<Directory "path/to/your/root/html/laravel">
</Directory>
</VirtualHost>
So all you need to do is change the directory path to point directly to your laravel folder inside of html directory.
If you do that, remove the lines you added in the .htaccess
RewriteCond %{REQUEST_URI} !^/laravel/
...
RewriteRule ^(/)?$ laravel/ [L]
And place the .htaccess file back in laravel directory so it can serve page directly from there.
I am using magento 1.8.1 and I want to add www in our url.
e.g: now my url is like http://example.com/
I want like http://www.example.com/.
I search on google and got this solution:
rewriteCond %{HTTP_HOST} !^www.example.com [NC]
rewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
referenced by
I dont know where to put this.
You need to follow below steps :
1 ) check in system >> configuration >> Web >> Unsecure and Secure check correct url are setup or not.
2) .htaccess changes :
RewriteCond %{HTTP_HOST} ^yoursitename.com$
RewriteRule (.*) http://www.yoursitename.com$1 [R=301]
The correct way to add the base url is in the system configuration, NOT rewrite rules in the .htaccess. First of all, make sure you have a CNAME record for www.example.com in your domain's zone file. Second, if you set http://www.example.com/ for your unsecure base url, and https://www.example.com/ for your secure base url, Magento will redirect to those urls during routing. For goodness sake, don't do any Magento redirection in your htaccess.
You can also set the redirect type code:
I have installed the SH404SEF component for Joomla 2.5. It is working in my live site , but does not work in localhost.
I have enabled the mod_rewrite and added htaccess in my localhost. but it is not redirecting and 404 error occurs. please Help
Create fresh installation of Joomla
After that check whether there is.htacsess file,
Else Create a .htaccess file and finally
Install the Sh404sef Component Using the Control Panel of Sh404sef
Start the SEF process and you can able to see the result
.htaccess Sample
At the End of .htaccess file , you will see
## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.
Consider changing the variable shDefaultParams['sh404SEF_USE_NON_STANDARD_PORT'. Guess it will work for you.
Been trying to resolve this problem with a rewrite rule that assigns a subdomain to a root directory of the same name, for example.
ddd.example.com will link to "/_projects/ddd" directory, that works fine and I have no trouble with it, the issue is that any files or directories I have in the root directory "/" can be accessed from the subdomain ddd.example.com.
Here is an example directory structure
example.com = "/"
"index.php"
ddd.example.com = "/_projects/ddd"
no files
So if for instance I access ddd.example.com/index.php, it will resolve to using the file located example.com/index.php which is located a directory below.
Here is the rewrite rule for .htaccess
# Skip rewrite if subdomain is www
RewriteCond %{HTTP_HOST} !^www\. [NC]
# Extract (required) subdomain to %1
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com(:80)?$
# Redirect to domain if requested URL does not resolve to existing subdirectory path
RewriteCond %{DOCUMENT_ROOT}/_projects/%1 !-d
RewriteRule (.*) http://example.com/ [NC,R=301]
# Skip rewrite if subdomain is www
RewriteCond %{HTTP_HOST} !^www\. [NC]
# Extract (required) subdomain to %1
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com(:80)?$
# Skip rewrite if requested URL does not resolve to existing subdirectory path or file
RewriteCond %{DOCUMENT_ROOT}/_projects/%1/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/_projects/%1/$1 -d
RewriteRule (.*) /_projects/%1/$1 [NC,L]
What if your RewriteConds fail? Then the URL falls through and is not rewritten. And so it accesses the document root. I would just create separate VirtualHost entries for every single supported subdomain. (How many are there?)
Suppose the client asks for http://sub.example.com/index.php.
Suppose that there exists an /_projects/sub/index.php.
Your RewriteCond-s will see that /_projects/sub/index.php exists as a file, and then skip the rewrite. But if the rewrite is skipped, then there is no redirect to /_projects/sub/. So what document is fetched in that case? You guessed it, /index.php.
You should unconditionally redirect these subdomains to their proper places (subject only to checks against looping).
Why did you split the rewrite into two, one doing an internal redirect? The internal redirect isn't rewriting the whole URL to example.com, and so it stays in the subdomain. It looks like you can get into a loop there.
My attempt at rewriting was to do this essentially.
Pseudo Code:
if (subdomain-directory != exists)
redirect them to the home page
else
rewrite the request for the subdomain
I could only accomplish that using two rules, I haven't found any other way to accomplish this, so this was my attempt.
The condition in question actually works fine, if I have an index.php in the /_projects/sub directory then it will use that file and the same for any other file I put in there.
I have absolutely no idea how I can accomplish this with mod_rewrite, I have played around with it for the best part of a few weeks to no avail, searched endlessly for possible solutions and have not made any progress.
Resolved the problem, seems that there was a looping problem that was breaking the rewrite.
##### Subdomain to subfolder
# Fix missing trailing slashes.
#RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
#RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.com$ [NC]
#RewriteCond %{DOCUMENT_ROOT}/%2%{REQUEST_URI}/ -d
#RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
# Rewrite sub domains.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.com$ [NC]
RewriteRule ^(.*)$ /projects/%2/$1 [QSA,L]
I've just created a new website and am ready to switch from an my current webserver to a new webserver.
The current webserver will be renamed www2
The new webserver will be known as www
I want to redirect all traffic from www2 to www except for one directory. My directory structure looks like this:
/var
/www
/html
index.html
page2.html
/orange
index.html
...
/archive
index.html
important-page1.html
important-page2.html
/turquoise
index.html
...
I would like to redirect everything to the equivalent www page
e.g. www2.mydomain.com/orange/index.html -> www.mydomain.com/orange/index.html
www2.mydomain.com/turquoise/index.html -> www.mydomain.com/turquoise/index.html
EXCEPT for the /archive folder. I would like users requesting :
www2.mydomain.com/archive/important-page1.html to view the page on www2 and not be redirected.
Do I use mod_rewrite or mod_redirect? And can I set this up in httpd.conf?
Thanks
Yes, you would need mod_rewrite.
Try:
RewriteEngine on
RewriteCond $1 !^archive
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]
Note: The 301 in R=301 is a permanent redirect, you'll need to change it to 302 if you want it to be temporary.
Within the VirtualHost config in httpd.conf (or httpd.conf.d file) for www2.mydomain.com add:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/archive.*
RewriteRule ^(.*)$ http://www.mydomain.com$1