PDA

View Full Version : [ubuntu] why my .htacces doesnt work?


maxidrom11
August 9th, 2008, 06:20 AM
I want to remove www. in mydomain.com using 301 redirect with .htaccess but it doesnt work for some reason :confused:

In my Apache 2. all needed .htaccess directives enabled I guess
mod_rewrite is enabled - I am sure

# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#

AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>



I set up Virtual hosting for mydomain.com


DocumentRoot "/var/www/path"
ServerName mydomain.com
ServerAdmin webmaster@domain.com
<Directory "/var/www/path">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>


my .htaccess file looks like this:

DirectoryIndex index.php
<FilesMatch .\.php>
ForceType application/x-httpd-php
</FilesMatch>
Options -MultiViews -Indexes +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^adser|ref|product\.php - [L]
RewriteCond $1 !(\.css)|(\.js)|(\.ico)|(\.swf)|(\.jpg)|(\.png)|(\ .gif)|(^widgets.*)$ [NC]
RewriteRule ^(.*)$ index.php [QSA,NC,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]

I dont understand why it doest redirect my site from www.mydomain.com to mydomain.com

maxidrom11
August 10th, 2008, 03:02 AM
problem solved
my .htaccess should look like this:

DirectoryIndex index.php
<FilesMatch .\.php>
ForceType application/x-httpd-php
</FilesMatch>
Options -MultiViews -Indexes +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
RewriteRule ^adser|ref|product\.php - [L]
RewriteCond $1 !(\.css)|(\.js)|(\.ico)|(\.swf)|(\.jpg)|(\.png)|(\ .gif)|(^widgets.*)$ [NC]
RewriteRule ^(.*)$ index.php [QSA,NC,L]

Dedoimedo
August 10th, 2008, 03:13 AM
Hi,
Good that you've solved it out, now a simple question:
Why didn't you try using the redirect directive?
Dedoimedo

maxidrom11
August 10th, 2008, 03:34 AM
Hi,
Good that you've solved it out, now a simple question:
Why didn't you try using the redirect directive?
Dedoimedo

'cos nobody posted a reply to my message

So let me see how my Redirect derective should look if I want redirect my site from www.mydomain.com to mydomain.com

by the way I dont want to redirect only one page

Dedoimedo
August 10th, 2008, 06:15 AM
Hello,

http://httpd.apache.org/docs/2.0/mod/mod_alias.html#redirect


Redirect works for any domain + all subdomains, so that my be what you want. Furthermore, you can use virtual hosts for multiple domains.

You can try my Apache guide, there might be useful answers in there you might like ...

Regards,
Dedoimedo

maxidrom11
August 11th, 2008, 04:13 AM
ok
I used this:
Redirect permanent http://www.domain.tld/ http://domain.tld/


it doesnt work at all :confused:

Dedoimedo
August 11th, 2008, 05:05 AM
Hello,
Is www a CNAME entry in your DNS record?
If so, then you need to remove it for this to work.
Dedoimedo