I try to redirect the whole website to an other domain, that is working !
But my case need that, if I tried to access to a subfolder (just one), I want to stay at this domain.
Here's my code
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !administrator
RewriteBase /
RewriteCond %{HTTP_HOST} ^domaine.com [NC]
RewriteRule ^/?(.*) http://www.domaine.fr/$1 [QSA,L,R=301]
RewriteCond %{HTTP_HOST} ^www.domaine.com [NC]
RewriteRule ^/?(.*) http://www.domaine.fr/$1 [QSA,L,R=301]
This RewriteCond is working in an other project that I took.
So does someone have an idea ?
Thank you !
RewriteBase line cannot come immediately after RewriteCond:
Just one rule will be enough for this task:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domaine\.com$ [NC]
RewriteRule ! administrator http://www.domaine.fr%{REQUEST_URI} [NC,L,R=301]
Related
I am having a problem with my htaccess file, and can't figure out if it's my configuration, or something like server cache which is messing with my URLs.
My file is the following
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^website.com$
RewriteCond %{HTTPS} off
RewriteRule (.*) https://website.com/$1 [R=301,L]
RewriteRule ^([a-z]+)\/?$ $1.php [NC]
The first rule is to move www to non-www, it works.
The second rule is to move http to https, it also works.
the third rule is to make URL /anyFile call anyFile.php, but keep a lovely URL.
The problem is that it calls anyFile.html, not PHP, and if I remove said HTML file then I get 404.
Yes it works typing anyFile.php in the URL, but I would like to not have .php in the URL.
If it is not obvious enough, it is supposed to work for any file name, not just a single one.
Any and all help is much appreciated.
Replace your .htaccess rules with this code:
Options -MultiViews
RewriteEngine On
RewriteBase /
# single rule for http->https and www removal
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ https://website.com/$1 [R=301,L]
# hide .php extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([a-z]+)/?$ $1.php [NC,L]
I'm recently learn how to do htaccess too, so I'm still a novice but I would write
RewriteRule ^([a-z]+)\/?$ helloWorld.php [NC]
to redirect it to the helloWorld.php file.
The $1 is a get parameter.
I am hosting multiple domains on one hosting account, so I have made folders in the public_html folder for each domain.
e.g. home/username/public_html/examplewebsite.com/
and
home/username/public_html/otherexamplewebsite.com/
I've been trying to figure out the code I need in my htaccess file to redirect visitors to the appropriate subfolder when they type in examplewebsite.com so that they don't see that they're in a subfolder of the main domain. I found this code originally, which was working:
Options -Indexes +SymLinksIfOwnerMatch
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/domainfolder/
RewriteCond %{HTTP_HOST} ^(www\.)?domainname\.
#Rewrite all those to insert /folder
RewriteRule ^(.*)$ /domainfolder/$1 [L]
but I also want to redirect all visitors who type in the naked domain to the www. version. I found this code, but when I use them both in the htaccess file you can see the subfolder name in the url again:
#Only www, no naked domain
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
I don't really understand much of all this code so If any of you gurus could help me figure out a solution I would really appreciate it!
Keep your rules like this in root .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{HTTP_HOST} ^(www\.)?domainname\. [NC]
RewriteRule !^domainfolder/ domainfolder%{REQUEST_URI} [L,NC]
Problem: I just did a major update to my companies website and trying to get some redirects to work. Right now if I have
Redirect 301 folder1/oldFile1.html http://www.mysite.com/newFolder1/newFolder2/newFile.html
and when you got to the new set up, I get this instead with a 404
http://www.mysite.com/newFolder1/newFolder2/newFile.htmloldFile.html
any ideas what is causing this?
Note: this only appears to happen to files that are moving from a 1 folder structure to a 2 folder structure.
RewriteOptions inherit
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^mysite.com [nc]
rewriterule ^(.*)$ http://www.mysite.com/$1 [r=301,nc]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html?\ HTTP/
RewriteRule ^(.*)index\.html?$ http://www.mysite.com/$1 [R=301,L]
Don't mix mod_rewrite rules with mod_alias rules.
Use this instead:
RewriteOptions inherit
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{http_host} ^mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,NC,L]
RewriteCond %{THE_REQUEST} \s/.*index\.html?\ HTTP/
RewriteRule ^(.*)index\.html?$ http://www.mysite.com/$1 [R=301,L]
RewriteRule ^folder1/oldFile1\.html$ /newFolder1/newFolder2/newFile.html? [R=301,L]
I´m trying to redirect an entire folder which is in domain.com/folder/templates1/, to a maintenance .html page, however I´m getting into a redirect loop with the next code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !/folder/templates1$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /mypage.html [R=302,L]
</IfModule>
Can anyone check this and let me know how could I avoid that loop?
Thank you in advance.
Try this rule:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule !^maintenance\.html /maintenance.html [R=302,L]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/folder/templates1 [NC]
RewriteRule . /mypage.html [R=302,L]
</IfModule>
Should do it. It should send any request starting with /folder/templates1 to /mypage.html, with a 302 (temporary redirect) status. What were you trying to do with the image files? Do you want them exempted? That wasn't in your specification, but can be added with one line:
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif)$ [NC]
Of course, you're on a server (Apache?) that recognizes .htaccess, and the mod_rewrite is enabled.
We made a mistake in the scope of our dynamic pages on a new site, and have some incorrect pages already spidered in Google.
I need to redirect the following format:
http://www.domain.com/dir/dir/?q=120
To this format:
http://www.domain.com/dir/dir/?p=120
Only difference is the 'q' needs to be a 'p'.
RewriteEngine is on, as I've already consolidated traffic from domain.com to www.domain.com
This is what I have in my root .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^centerline.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
RewriteRule ^(/leadership/detail/)\?q=([0-9]+)$ $1?p=$2 [R=301, L]
Try this:
RewriteCond %{QUERY_STRING} q=([0-9]+)$
RewriteRule ^(.*)$ /$1?p=%1 [L,R=301]
You'll need the RewriteCond as apache doesn't allow matching against the querystring in a RewriteRule
EDIT
RewriteCond %{REQUEST_URI} ^/leadership/detail/$
RewriteCond %{QUERY_STRING} q=([0-9]+)$
RewriteRule ^(.*)$ /$1?p=%1 [L,R=301]