There's some misconfiguration in my htaccess which I can't solve :/
Here's the htaccess:
RewriteEngine on
RewriteRule ^([^\.]+)/?$ index.php?page=$1
rewritecond %{http_host} ^domain.com [NC]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,L]
The .htaccess actually works fine, except in one case: When I connect to a subpage to the root domain without "www.", like this:
http://domain.com/somestuff
Then the first rule doesn't apply and I get redirected to:
http://www.domain.com/index.php?page=somestuff
What have I done wrong?? Thanks for any suggestions!
Try moving
RewriteRule ^([^\.]+)/?$ index.php?page=$1
below
RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,L]
Related
I want to write a rule in htaccess that always redirects http://example.com/index.aspx or http://www.example.com/index.aspx to http://example.com.
This is what I have tried so far:
RewriteCond %{REQUEST_URI} ^/index.aspx [NC]
RewriteRule ^(.*)$ http://%1 [R=301,L]
but it's not working properly.
Thanks
You can use just one rule:
RewriteRule ^index\.aspx$ http://%{HTTP_HOST} [NC,R=301,L]
I have a site: blog.example.com.
I want blog.example.com to go to example.com/news
But I want blog.example.com/tag/mytag or blog.example.com/category/mycategory to go to example.com/tag/mytag or example.com/category/mycategory
So far I have my .htaccess like this but of course it doesnt work:
RewriteEngine on
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteRule ^(.*)$ http://www.example.com/news/ [R=301,L]
You can use this in root .htaccess of blog.example.com:
RewriteEngine on
RewriteRule ^/?$ http://www.example.com/news [R=301,L]
RewriteRule ^(.+)$ http://www.example.com/$1 [R=301,L,NE]
I have an URL as :
http://mydomain.com/site/?cmd=home
I want to change the above address to http://mydomain.com/home
i am using .htaccess file like this:
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ /site?cmd=$1 [L]
I am not sure where is the problem?
Thanks in advance
The Rule works the other way around: you want to get from /site/?cmd=home to /home, but with your RewriteRule you are redirecting to /site?cmd= (Probably there is a mistake somewhere?)
If you want to redirect from /site/?cmd=home to /home, like the question states, use the following:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/site
RewriteCond %{QUERY_STRING} ^cmd=(.*)$
RewriteRule ^(.*)$ /%1/? [R=302,L]
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} /site\?cmd=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
# internal forward from pretty URL to actual one
RewriteRule ^([^/.]+)/?$ /site?cmd=$1 [L]
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]