How to rewrite urls - url

I have a site at xyz.com, for some reasons I want to redirect access to www.xyz.com to the url xyz.com. Even if they add 'www', I want to alter the address in their bar to xyz.com. Is there a way?

First enable mod_rewrite in your web server then use
.htaccess file in your directory with this content:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.xyz\.com$
RewriteRule ^(.*)$ "http\:\/\/xyz\.com\/$1" [R=301,L]

Related

How can I force a URL to have "www." no matter what?

I'm using Joomla 1.5 and Virtuemart 1. It might seem like a weird question but I need my URL to have "www." written in the URL at all times. If the URL doesn't have "www." then the cart functions don't work. If it does have it, then it does work.
Is there a way I can force this? I am using Parallels Plesk 10.3.1 if I can do it on there.
if your server is running on apache, you can add a .htaccess file to your root webdirectory with the following content:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

URL be able to not type .php in url and direct to php file

i want to make this page http://www.jambagames.com/index.php to not show the ".php" at the end. Is it also possible to make php files my default on my godaddy server? Such as typing in http://www.jambagames.com/index and it'll go to that index.php page.
The process that you are asking here is to rewrite the URL's
To rewrite http://www.jambagames.com/index.php into http://www.jambagames.com/index you need to use these directives in your .htaccess file:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

Best way to redirect non-www to www?

What would be the best way to redirect my non-www urls to www url in my site.
I think they are being redirected with a 301 redirect now but traffic that is being sent to my non-www is not tracked properly with google analytics.
So I guess it's not configured properly.
Hope someone can help.
Thanks
A non-www to www can be done using Apache Rewrite Engine and htaccess file.
Create a .htaccess file in your public html directory with following content..
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.youraddress.com$ [NC]
RewriteRule ^(.*)$ http://www.youraddress.com/$1 [R=301,L]

Append www in URL for both HTTP and HTTPS

I have some pages on my website that use http and other pages that use https. Now I want to use mod_rewrite to append www to all URLs whether they use http or https.
I have my current code in .htaccess:
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index.php
RewriteCond $1 !^(index\.php|public|assets|robots\.txt)
RewriteRule ^(.*)$ ./index.php/$1 [L]
Please only focus on the first two lines as the rest are for other rewrite rules but I included it in case they were causing any errors for my first 2 lines.
Now this redirects all pages to http, but I want pages using https to be redirected to the right protocol. I tried the solution to a thread on StackOverflow (htaccess redirect for non-www both http and https) but it doesn't work for me.
The answer you linked should work perfectly. If it isn't working, the HTTPS variable probably isn't set. This usually happens because you're not doing the HTTPS on your apache server. Perhaps you have a proxy that does it, or a load balancer? In that case you need to make sure the HTTPS variable gets set. Something like this often does the trick (the example works for amazon elastic load balancers):
SetEnvIf X-Forwarded-Proto https HTTPS=1

mod_rewrite rule to check for maintenance page except for certain subdomains

I have configured Apache to look for the presence of a maintenance page and redirect to that page if it is present:
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.
RewriteRule ^.*$ /system/maintenance.html [L]
This is fairly standard practice for deploying Ruby on Rails apps.
What I'd like to do to create a URL exclusion list so the redirect doesn't occur for specific subdomains, e.g: https://user1.myapp.com/any_request_url or https://user2.myapp.com/any_request_url
Can this be achieved with extra RewriteCond statements?
This should do it:
RewriteCond %{HTTP_HOST} !^(user1|user2)\.myapp\.com$

Resources