I have this code in my .htaccess to make my URLs SEO friendly and pretty:
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?page=$1 [L,QSA]
Now I notice that a subfolder (gallery.mysite.com ) set by my webhotel does no longer work. It gets redirected to index.php and seems to try to load an empty var (page).
Is there a way to force the subdomain not getting redirected?
I have tried this but it doesn't quite get there...
RewriteCond %{HTTP_HOST} ^gallery\.mysite\.com$ [NC]
RewriteRule ^((?!sub1/).*)$ sub1/$1 [L,NC]
RewriteCond %{HTTP_HOST} !^gallery\. [NC]
You can use this
RewriteCond %{HTTP_HOST} !^gallery\.mysite\.com$
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?page=$1 [L,QSA]
Related
Motive: What I am trying to do is use parked domain and redirect it to subdirectory. and in subdirectory I have a script that needs pretty url's and htaccess is the only thing I can use.
Code in main .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteBase /
RewriteRule ^info/(.+)$ contact.php?a=$1
RewriteRule ^list/(.+)/page/(.+)$ list.php?a=$1&p=$2 [L]
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteRule ^(.*)$ http://www.example.com/m/$1 [R=301]
Code in /m .htaceess
RewriteEngine On
RewriteBase /
RewriteRule ^how/(.+)$ how.php?a=$1
RewriteCond %{HTTP_HOST} ^(www.)?main-example.com$ [NC]
RewriteCond %{REQUEST_URI} ^/m/(.*)$
RewriteRule ^(.*)$ - [L,R=404]
What i want is to achieve when user visits www.example.com/m/how/love the script should treet a get variable of a something like www.example.com/m/how.php?a=love but url should
remain pretty.
What my current code does is unlimited redirects to /m/404.shtml giving 301 in firebug.
I have make virtual subdomain in my code.like below
RewriteCond %{HTTP_HOST} ^(.*)\.mysitename\.com
RewriteRule ^(.*)$ agent.php?asitename=%1 [L,NC,QSA]
it works fine, but it did not work for pages like
RewriteCond %{HTTP_HOST} ^(.*)\.mysitename\.com
RewriteRule ^(.*)/ag_buy.html ag_buy.php?sitename=%1&page=buy [L,NC,QSA]
it redirect all pages top agent.php, but it should only redirect home page to agent.php, for other pages it should work like ag_buy.html to ag_buy.php
and so on.........
please guide me on htaccess how can i make this possible.
The ^(.*)$ matches everything, if you only want the home page, then change it to ^$:
RewriteCond %{HTTP_HOST} ^(.*)\.mysitename\.com
RewriteRule ^$ agent.php?asitename=%1 [L,NC,QSA]
Try to replace the first rule with following code:
RewriteCond %{HTTP_HOST} ^(.).mysitename.com
RewriteCond %{REQUEST_URI} =/
RewriteRule ^(.)$ agent.php?asitename=%1 [L,NC,QSA]
I am not a new developer and have worked with .htaccess for years, but today I'm totally stuck and have no idea what is going on. Below is my full htaccess file:
Options All -Indexes
ReWriteEngine On
RewriteRule ^page/([a-zA-Z0-9_-]+)$ page.php?pageurl=$1
RewriteRule ^([a-zA-Z0-9_-]+)$ category.php?categoryurl=$1
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+)-([a-zA-Z0-9_-]+)$ product.php?category=$1&subcategory=$2&productid=$3&producturl=$4
RewriteCond %{HTTP_HOST} www.website\.com$ [NC]
RewriteRule ^(.*)$ http://website.com/$1 [R=301,L]
website.com/category should take me to the category page which it does, but for some reason the url gets changed, as if htaccess is working in reverse, I get sent to website.com/category.php?categoryurl=category.
This is exactly the same for the other ones, my product page should be website.com/category/subcategory/123-producturl but it redirects too:
website.com/product.php/category/123-producturl?category=category&subcategory=subcategory&productid=123&producturl=producturl
Anybody have any idea at all why this is doing what it is?
Try this one, you have not added flags to end the line in HTACCESS.
Options All -Indexes
ReWriteEngine On
RewriteRule ^page/([a-zA-Z0-9_-]+)$ page.php?pageurl=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)$ category.php?categoryurl=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+)-([a-zA-Z0-9_-]+)$ product.php?category=$1&subcategory=$2&productid=$3&producturl=$4 [L]
RewriteCond %{HTTP_HOST} www.website\.com$ [NC]
RewriteRule ^(.*)$ http://website.com/$1 [R=301,L]
Im using the following in my htaccess
RewriteCond %{HTTP_HOST} !^www
RewriteRule ^(.*)$ http://www.website.com [R=301,L]
This works except that i have urls like this website.com/name?query=1
The rewrite is removing the /name when typing the url with non-www
so website.com/name?query=1 will rewrite to www.website.com/?query=1
Also im using Zend Framework and have the default /public folder when using
RewriteCond %{HTTP_HOST} !^www
RewriteRule ^(.*)$ http://www.website.com/$1 [QSA,R=301,L]
in the rewrite it makes the link look like this www.website.com//public/name?query=1
I need to not have it NOT write //public and I don't want to change the structure of the site because there are to many pointers to the /public folder
How do I get the RewriteRule to change non-www to www and not drop "name" ?
Try this.
# No W's to W's keeping all the URI items intact
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www\.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www
RewriteRule ^(.*)$ http://www.website.com/$1 [QSA,R=301,L]
What would be the best way to redirect codeigniter website to www domain? The only way that comes to my mind is to use htaccess for this but can't figure out exactly how. This is the rewrite rule I'm using right now to remove index.php from the url. How should I add the redirection to www domain correctly?
RewriteEngine on
RewriteCond $1 !^(index\.php|images|assets|uploads|robots\.txt|favicon\.png|favicon\.ico)
RewriteRule ^(.*)$ index.php/$1 [L]
See this URL
.htaccess Redirect non-WWW to WWW preserving URI string
Or try it
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www.mysite.com [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
Another example
See this URL
Codeigniter redirects for a new domain
Try it
Try adding the following to the .htaccess file in the root directory of your www.xyz.com site.
RewriteEngine on
RewriteBase /
#redirect www.xyz.com/A/B/controller/function
#www.xyz.com/B/controller/function
RewriteCond %{HTTP_HOST} ^www\.xyz\.com$ [NC]
RewriteRule ^A/(B/[\w]+/[\w]+)$ /$1 [L,NC,R=301]
#redirect www.xyz.com/A/controller/function to
#www.abc.com/controller/function
RewriteCond %{HTTP_HOST} ^www\.xyz\.com$ [NC]
RewriteRule ^A/([\w]+/[\w]+)$ http://www.abc.com/$1 [L,NC,R=301]
Use a CNAME record in your DNS.
This saves an HTTP request so is the most efficient option.
Add another condition under that:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]