I use 301 redirect from non-WWW to WWW domain! Works fine, but links are different.
Example:
from - ggkj.com/posts/godzilla/43
to - www.ggkj.com/index.php?view=posts&author=godzilla&aid=43
my .htaccess 301 redirect code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*) http://www.example\.com/$1 [L,R=301]
.htaccess code: http://pastebin.com/t3FA59uq
This is currently what i use on my website with success:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} !^www.walterbax.ca [NC]
RewriteRule ^(.*)$ http://www.walterbax.ca/$1 [R=301,L]
EDIT: after looking into your question a little further I can tell you that your issue is improperly placed in the file. it must be hitting another rule that is rewriting it into URL variables.
I would start with a basic htaccess for the www. rule for testing and add to it from there.
Try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com$
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
Related
I'm looking for a way to do something like this in .htaccess:
This.is.my-website.com
Please note: This.is is the rewrite to the directory This.is and mywebsite.com is the URL of the site. I want all requests to the site to be redirected to that folder (301?). Is it possible to achieve this in .htaccess?
Try:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.my-website.com$ [NC]
RewriteRule ^(.*)$ /%1/$1 [L]
for an internal rewrite (won't change the URL in browser's address bar).
Or to externally redirect:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.my-website.com$ [NC]
RewriteRule ^(.*)$ http://my-website.com/%1/$1 [L,R=301]
I am trying to redirect old url to new url but it is not redirecting.
Old url: http://domain.com/STACK/App/
New url: http://domain.com/stack-app
And my .htaccess file
Redirect 301 /STACK/App http://domain.com/stack-app
Thanks,
Try this code.
RewriteEngine on
RewriteRule http://domain.com/STACK/App/ /http://domain.com/stack-app [R=301,L]
For more help go to this link:--
http://edward-designer.com/web/htaccess-url-rewrite-simplified/
You can use this rule as your very first redirect rule in your root .htaccess:
RedirectMatch 301 ^/STACK/App/?$ /stack-app
Within the mod_rewrite section of your .htaccess file, add the following lines on the old site:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com\STACK\App\$
RewriteRule (.*)$ http://domain.com/stack-app/$1 [R=301,L]
</IfModule>
you can use the following code to redirect your website using .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !oldexample.com$ [NC]
RewriteRule ^(.*)$ http://www.newexample.com/$1 [L,R=301]
for non www version, you can use the following,
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !oldexample.com$ [NC]
RewriteRule ^(.*)$ http://newexample.com/$1 [L,R=301]
I am having error in rewriting url. I want the request
http://go.example.com/all-pathnames-flenames
should be handled by some page
http://www.example.com/myfile.php
It should not be hard or 301 redirect (rather original url should be there).
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^go\.example\.com$ [NC]
RewriteRule ^(.*)$ /myfile.php [L]
above mentioned is the code i have but it is not working
You need to exclude rewriting myfile.php, otherwise you'll create a loop:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^go\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/myfile.php
RewriteRule ^(.*)$ /myfile.php [L]
I am trying to rewrite my .htaccess file to redirect old dynamic URLS to new ones.
I have tried these so far but they are not working as expected. The second rule seems to redirect to the first one.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule ^(.*)$ "http\:\/\/www\.mydomain\.com\/$1" [R=301,L]
Redirect 301 /product.php?l=old-product-name1 http://www.mydomain.com/product.php?l=new-product-name1
Redirect 301 /product.php?l=old-product-name2 http://www.mydomain.com/product.php?l=new-product-name2
Can anyone help me redirect these properly?
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule ^(.*)$ "http\:\/\/www\.mydomain\.com\/$1" [R=301,L]
RewriteCond %{QUERY_STRING} =l=old-product-name1
RewriteRule ^product.php$ http://www.mydomain.com/product.php?l=new-product-name1 [R=301]
I am having a problem with redirecting a page from example.com (to) www.example.com
The code I have is:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.subdomain.domain.com/$1 [L,R=301]
And it is not working, any help?
All you need to do is force the www version of your domain? Just do this...
# Force www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
This is what my rewrite looks like, and it works:
## REWRITE RULES
# enable rewrite
RewriteEngine On
RewriteBase /
# enforce a specific domain in the url
RewriteCond %{HTTP_HOST} !^www\.sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.sub.domain.com/$1 [R=301,NC,L]
This rule will redirect anything that is NOT www.sub.domain.com to www.sub.domain.com.
Update: based on your comment It does not redirect and it gives me the openDNS page, I believe your problem is not (yet?) with mod_rewrite.
Try adding Options +FollowSymlinks before RewriteEngine On, then add RewriteBase / after RewriteEngine On.
I recommend reading sections Fatal Redirection and rewrite logging found here.
You can enable mod_rewrite debugging to see what is going on (if anything!):
RewriteLog "/tmp/rewrite.log"`
RewriteLogLevel 5