What is wrong with this code, I thought it was working but it appears not to be now, any help?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^forum.ohmsgaming.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.forum.ohmsgaming.com$
RewriteRule ^/?$ "http\:\/\/ohmsgaming\.com\/community\/forum\/" [R=301,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^outhousemouse.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.outhousemouse.com$
RewriteRule ^/?$ "http\:\/\/ohmsgaming\.com" [R=301,L]
</IfModule>
You don't need to escape the RewriteRule values. That might be your problem.
Example:
RewriteRule ^/?$ http://ohmsgaming.com/community/forum/ [R=301,L]
When in doubt, turn on rewrite logging:
RewriteLog /var/log/apache2/MYDOMAIN_rewrite.log
RewriteLogLevel 5
This log can be viewed using tail -f /path/to/log, then reload the page. It will clearly list the processing going on.
Edit
I just noticed that the conditions are not escaped, they should look like:
RewriteCond %{HTTP_HOST} ^forum\.ohmsgaming\.com$
Related
I have two domains:
www.mywebsite.com
www.my-website.com
I want all traffic going to my-website.com (no www.)
In the .htaccess for www.mywebsite.com I currently have the following:
RewriteCond %{HTTP_HOST} ^mywebsite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com$
RewriteRule ^/?$ "http\:\/\/www\.my\-website\.com\/" [R=301,L]
In the .htaccess for www.my-website.com I currently have the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^111\.111\.111\.111
RewriteRule (.*) http://www.my-website.com/$1 [R=301,L]
I am looking for the correct way to write both .htaccess files so everything goes to my-website.com and prevent from running in parallel.
in www.mywebsite.com .htaccess I entered the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mywebsite.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mywebsite.com$
RewriteRule (.*)$ http://my-website.com/$1 [R=301,L]
</IfModule>
in www.my-website.com I entered the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-website\.com
RewriteRule (.*) http://my-website.com/$1 [R=301,L]
Alright. I'm having no luck. So I figured I'd see if you all could help make some sense of this issue.
I've inherited a site that previously had a lot of different subdomains, which have now all been written into the .htaccess file to rewrite as subdirectories (i.e., blog.site.com becomes site.com/blog).
To avoid duplicate content issues, I also need to rewrite all site.com URL's as www.site.com. And even though the current rules look good to me, they're apparently not rewriting all the subdirectories of the domain. (I've never been that great with RegEx, so that could be part of the problem.)
Here are the current rules from .htaccess:
#---------------------------------
# Start rewrite engine
#---------------------------------
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{PATH_INFO} !^$
RewriteCond %{HTTP_HOST} !^localhost$ [NC]
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteCond %{HTTP_HOST} !^blog\..+$ [NC]
RewriteCond %{HTTP_HOST} !^docs\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
#---------------------------------
# Rewrite some of our subdomains
#---------------------------------
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.site\.com$ [NC]
RewriteRule (.*)$ "http://www.site.com/blog/$1" [R=301,QSA,L]
RewriteCond %{HTTP_HOST} ^docs\.site\.com$ [NC]
RewriteRule (.*)$ http://www.site.com/docs/$1 [R=301,QSA,L]
RewriteCond %{HTTP_HOST} ^wiki\.site\.com$ [NC]
RewriteRule (.*)$ http://www.site.com/wiki/$1 [R=301,L]
</IfModule>
#---------------------------------
# Wordpress specific - do not place anything below this line
#---------------------------------
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
(Obviously, some of them exist to allow for a local dev environment, etc).
Any thoughts on why I'm not seeing site.com/directory rewritten as www.site.com/directory? What am I missing here?
I moved my site to a new php 5.2 server with no access to apache conf files
So I had to put site's rewrite rules into an .htaccess (wildcards is open for the domain)
and I expirience a lot of issues with it now
ORIGINAL WAS
Options +FollowSymLinks
rewriteEngine on
rewriteCond $1 !^pages/
rewriteCond %{HTTP_HOST} !^www\.mydomain\.com
rewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com
rewriteRule (.*) /pages/%1/$1
rewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /pages/
rewriteRule ^pages/([^/]+)/(.*)$ http://$1.mydomain.com/$1 [R=301,L]
What changes Do I need to make ?
the whole point is that I need to redirect:
www.mydomain.com/pages/XXXXX.php ==>
XXXXX.mydomain.com/...whatever....
but also
www.mydomain.com/pages/XXXXX/...whatever.... ==> XXXXX.mydomain.com/...whatever....
The rules below should do what you requested.
However, in the first example, where does the whatever appear in the original request to www.mydomain.com/pages/XXXXX.php.
If the whatever refers to the query string, then it should work.
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
#redirect www.mydomain.com/pages/XXXXX.php to XXXXX.mydomain.com/
RewriteRule ^pages/(.+)\.php http://$1.mydomain.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
#redirect www.mydomain.com/pages/XXXXX/.whatever.. to XXXXX.mydomain.com/...whatever
RewriteRule ^pages/([^/]+)/(.*) http://$1.mydomain.com/$2 [R=301,L]
You could try the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^pages/
RewriteRule ^pages/([^/]+)(?:\.php|/(.*))$ http://$1.mydomain.com/$2 [R=301,L]
RewriteCond %{REQUEST_URI} !^pages/
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com
RewriteRule (.*) /pages/%1/$1 [L]
</IfModule>
And one more: please make sure whether you REALLY NEED the Options +FollowSymLinks directive as this might cause an internal error if not allowed or already set in httpd.conf
I'm trying to rewrite my URL's subdomain.
http://username.domain.com >>> http://www.domain.com/user.php?u=username
I'm using this for my .htaccess
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com
RewriteRule .* /user.php?u=%1 [L]
Can you help me for debugging this problem ?
(Username's can contain a-z 0-9 and hypens)
Also if subdomain is www or api, don't redirect them
Try this one
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com
RewriteRule ^(.*)$ /user.php?u=%1 [L]
I have the same use case and its working for me
EDIT:
Add this to your httpd.conf file and try debugging
<IfModule mod_rewrite.c>
RewriteLog "F:/wamp/www/logs/rewrite.log"
RewriteLogLevel 3
</IfModule>
I am new to .htaccess redirection.
I am using the below code
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
But when i hit the URL http://example.com/folder/file.php i'm getting redirected to http://www.example.com/file.php which is wrong.
Can someone please help me with this
Help is greatly apreciated
Thanks
Alright can you try this in your .htaccess or apache conf file:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
There are some typos and some unescaped characters, but most important you're missing a needed "$" character in that *rewritecond %{http_host} ^example.com [nc]* line.
Here is your code "as it should have been":
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC]
Though, I personally use and would recommend doing it like this:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^!www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC]
That should get you going... ;)