Been fidling with it my self but I think I am doing it all wrong, please advice:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !\-f
RewriteRule ^folder1(.*)$ https://newdomain.com$1 [L,R=301]
RewriteRule ^folder2(.*)$ https://newdomain.com/$1 [L,R=301]
RewriteRule ^folder3(.*)$ https://newdomain.com/somefolder/$1 [L,R=301]
RewriteRule ^page1\.html https://newdomain.com/$1 [L,R=301]
RewriteRule ^page2\.html https://newdomain.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^/?$ https://newdomain.com/ [L,R=301]
</IfModule>
If I request a page/folder for olddomain.com which is not in .htaccess it should not rewrite.
Does anyone have more skills in .htaccess than me?
Thanks,
Marc
Probably you should prepend an additional condition among the ones about newdomain
RewriteCond %{HTTP_HOST} ^(www\.)?newdomain\.com$ [NC]
Related
I have a problem that I don't understand with symfony. I would like to force https and www on my .htaccess, but I don't understand anything with symfony.
Here is my .htaccess inside www file
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L]
And in my public file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
I don't know what I need to write and where ...
Include in your .htaccess file:
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The first two lines are for redirecting to https, the second two lines for www.
try this in your .htaccess file :
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .? https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
I have website on Phalcon and everything works fine (I have SSL) but now I would like to have an access to the forum (https://www.example.com/forum/) but I have a problem with the .htaccess configuration.
Phalcon have the specific config:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
What is the correct configuration for home domain and /forum/ folder?
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^ "http://www.example.com%{REQUEST_URI}" [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ "https://%{SERVER_NAME}%{REQUEST_URI}" [R,L]
RewriteCond %{REQUEST_URI} !^/forum/
RewriteRule ^.*$ public/$0 [L]
Phalcon's root .htaccess file redirects all traffic to /public folder.
What you need to do is add one more condition to your final rewrite rule. Here is portion of my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
# Force www
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]
# Forward to public/
RewriteRule ^(forum)($|/) - [L]
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
This RewriteRule ^(forum)($|/) - [L] is the important condition you need to add before RewriteRule ^.*$ public/$0 [L]
Also you can add as much as rules you want to allow multiple folders.
RewriteRule ^(forum)($|/) - [L]
RewriteRule ^(some-other-folder)($|/) - [L]
...
I have a 301 redirect on the domain goodereader.com that points to goodereader.com/blog/
I wanted to setup a forum, and wanted to exclude /forum/ from being 301'd
Here my current .htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/forum/.*$
RewriteCond %{HTTP_HOST} ^www\.goodereader\.com$ [NC]
RewriteRule ^(.*)$ http://goodereader.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^goodereader\.com$
RewriteRule (.*) http://goodereader.com/blog/$1 [R=301,L]
RewriteRule ^$ blog [L]
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
From the comments, you can fix this by adding the same condition to the 2nd rule. Rewrite conditions only get applied to the immediately following rule, they're not global in any way.
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/forum/.*$
RewriteCond %{HTTP_HOST} ^www\.goodereader\.com$ [NC]
RewriteRule ^(.*)$ http://goodereader.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI} !^/forum/.*$
RewriteCond %{HTTP_HOST} ^goodereader\.com$
RewriteRule (.*) http://goodereader.com/blog/$1 [R=301,L]
RewriteRule ^$ blog [L]
or use a pass through:
RewriteEngine On
RewriteRule ^forum/ - [L]
RewriteCond %{HTTP_HOST} ^www\.goodereader\.com$ [NC]
RewriteRule ^(.*)$ http://goodereader.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^goodereader\.com$
RewriteRule (.*) http://goodereader.com/blog/$1 [R=301,L]
RewriteRule ^$ blog [L]
Make sure to clear your browser's cache. 301 redirects are permanent and the browser will always cache them.
//here is my htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^glamestates\.co\.uk$ [NC]
RewriteRule ^.*$ http://www.glamestates.co.uk%{REQUEST_URI} [R=301,L] # <-- Mind the 'L'!
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
where about to add this google webmaster tools link in my htaccess
glamestates.co.uk/googlec7feca3a4513beef.html
what I have got so far but this doesn't work. I added in line five
RewriteRule ^glamestates\.co\.uk\googlec7feca3a4513beef\.html$ http://www.glamestates.co.uk\googlec7feca3a4513beef.html%{REQUEST_URI} [R=301,L]
I have already put this question here since many day nobody answered
Still not 100% clear about what you're asking, but I think perhaps you want this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^glamestates\.co\.uk$ [NC]
RewriteRule ^googlec7feca3a4513beef\.html$ $0 [L]
RewriteRule ^.*$ http://www.glamestates.co.uk%{REQUEST_URI} [R=301,L] # <-- Mind the 'L'!
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
just need to paste the googlec7feca3a4513beef.html file into Webroot folder rather than Root
I want to redirect this php url to the folder.
I always used the settings below. But since the update of apache to 2.4 it doesnt work anymore.
Goal:
example.com/about.php?sub=about or example.com/about.php?sub= should be seen in the browser as example.com/about/
I use the following settings.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(example.com)(:80)? [NC]
RewriteRule ^(.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]
RewriteRule ^about/$ about.php$1 [L]
RewriteRule ^about/([A-Za-z0-9-]+)$ about.php?sub=$1 [L]
This is what I am using now...
I don't see any rule in your code that is making /about.php?sub= to /about.
Try this code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(about)\.php(\?sub=[^\s&]*)?\s [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteRule ^about/?$ about.php?sub=about [L,NC,QSA]
RewriteRule ^about/([a-z0-9-]+)/?$ about.php?sub=$1 [L,NC,QSA]
# Add trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R]