Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am using the following in my .htaccess file to force https on any user that is visiting my website without https in the url.
However, if the user visits https://www.mysite.co, I want to be able to remove the www from the request.
Please can you tell me what I need to modify in my .htaccess file in order to remove the www from the url while maintaining the forceful https?
Thanks,
Max.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mysite.co/$1 [R,L]
Do it with 2 rewrites.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://mysite.co/$1 [R,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ https://mysite.co/$1 [R,L]
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Actually i want to make auto redirect when open
from
test.com/login.php
to
test.com/login/
What should i put on my htaccess file.
You'd first redirect to pretty-url if the raw request matches:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /login\.php [NC]
RewriteRule ^login\.php$ /login/ [R=301,L,NC]
Now, you deal with the rewritten url to internally redirect to correct page:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^login/?$ /login.php [NC,L]
Have you tried something?
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^index/?$ index.php [NC,L]
Your rewrite module should be enabled for doing this?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have my website name as www.example.com but the 'example' is not related to any of my keywords.
But my competitors have. Is there any solution for index page?
All others Page maintains the proper naming_standard but for index page it creates a problem.
Here's my .htaccess code
RewriteCond %{HTTP:Host} ^example\.com$
RewriteRule (.*) http\://www.example.com$1 [NC,R=301,U]
RewriteRule ^/index.cfm$ http\://www.example.com [NC,R=301,U]
RewriteRule ^/main.cfm$ http\://www.example.com [NC,R=301,U]
RewriteRule ^/ww.example.com$ http\://www.example.com [R=301,L]
RewriteCond %{HTTP:Host} ^ww.example\.com$
RewriteRule (.*) http\://www.example.com$1 [NC,R=301,U]
Try this instead:
RewriteRule ^/index.cfm / [NC,R=301,L]
RewriteRule ^/main.cfm / [NC,R=301,L]
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
The first two rules stop people going to index.cfm and main.cfm directly and redirects them to the base URL.
The third condition and fourth rule check the domain is "www.example.com" and if it is anything else, e.g. without the www. or an alias, 301 redirects them to the same page on "www.example.com".
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I ve looked into many examples in stackoverflow and couldn't find a working solution for me.
I have a wordpress blog set up in a subdirectory.
The blog sits under www.domain.co.uk/wordpress/
In order for my permalinks to work I did an htaccess rewrite rule which is this
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?domain.co.uk$
RewriteRule ^(/)?$ http://domain.co.uk/wordpress [L]
Is there a way to take out the /wordpress part on the URL?
I need it to point there but I want the /wordpress to be removed.
Any ideas?
I have now managed to solve this issue following this guide: http://www.optiniche.com/blog/145/wordpress-tutorial-install-wordpress-in-a-different-directory/
Remove the wordpress from the redirect in your rule (the http://domain.co.uk/ means there's an implicit redirect) and add a specific rule to internally rewrite instead:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.co.uk$ [NC]
RewriteRule ^ http://domain.co.uk/ [L,R=301]
# now silently rewrite to wordpress
RewriteCond %{REQUEST_URI} !^/wordpress
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wordpress/$1 [L]
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have been trying to redirect all requests under a domain to an underconstruction folder with the following:
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/underconstruction/
RewriteRule ^ /underconstruction/ [R=301]
But it doesn't seem to work.
I tried this (and it works):
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/underconstruction/underconstruction.html
RewriteRule ^ /underconstruction/underconstruction.html [R=301]
But I don't see the images and CSS that it comes with it.
Does anyone have any idea?
Maybe one solution is to exclude all image and CSS files from the rule, like this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
# Add or remove file types in the next line if necessary.
RewriteCond %{REQUEST_URI} !\.(css|jpg|png|gif|bmp|js) [NC]
RewriteCond %{REQUEST_URI} !underconstruction\.html [NC]
RewriteRule .* /underconstruction/underconstruction.html [R=302,L]
Other options are to replace relative with absolute paths in the links to those files or to use the BASE element as described in this answer
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I am trying to use mod_rewrite to basically port forward a port on a subdomain to another port on another IP.
Like this:
sub.website.com:2000 --> 123.45.67.891:3000
How could this be accomplished using a .htaccess file with mod_rewrite?
I have tried the following but to no avail:
RewriteCond %{HTTP_HOST} ^sub.website.com$ [NC]
RewriteCond %{SERVER_PORT} ^2000$
RewriteRule ^(.*)$ https://123.45.67.891:3000/$1 [L,R=302]
Playing with your rules, I found out that HTTP_HOST includes the port number. So the rules should look like
RewriteCond %{HTTP_HOST} ^sub.website.com:2000$ [NC]
RewriteCond %{SERVER_PORT} ^2000$
RewriteRule ^(.*)$ https://123.45.67.891:3000/$1 [L,R=302]
If you want to test against server name alone, you could use %{SERVER_NAME} as #faa suggested in the comments
RewriteCond %{SERVER_NAME} ^sub.website.com$ [NC]