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]
Related
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]
i am Working on a redirect script
i want to redirect all links contaning /en/
For eg redirect link like this
http://example.com/en/some-text/123-some-text-123456.html
to
http://example.com/some-text/123-some-text-123456.html
I am trying with this script but not workin as of now
RewriteEngine on
RewriteCond %{HTTP_HOST} (.*)\en\(.*)
RewriteRule http://www.example.com/$1 [R=301,L]
Any help would be appreciated
Thanks!
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/en/(.*) [NC]
RewriteRule .* http://www.example.com/%1 [R=301,L]
Use this - with the %1 modifier you can access the extract group from the previous RewriteCond.
It is simple by using this
Redirect 301 http://example.com/en/(.*)$ http://example.com/$1
Here is my initial redirect rule:
RewriteCond %{HTTP_HOST} !^sub1\.myinitialdomain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^sub2\.myinitialdomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [L,R=301]
That basically redirects the entire website, except for sub1 and sub2 to the new domain.
However, I've got a wordpress install at /wordpress and I've got the following rule in place to redirect all of the articles:
RewriteCond %{REQUEST_URI} wordpress
RewriteRule ^(.*)$ https://www.mydomain.com/blog/$1 [R,L]
But even though the articles are being redirected correctly, the main /wordpress directory is not being redirected correctly. It's being redirected to https://www.mydomain.com/blog/wordpress
I need to be able to combine the rules, but make sure that /worpress and any articles within that are being redirected to https://www.mydomain.com/blog/
You can use this rule to redirect everything from within /wordpress/.htaccess file:
RewriteEngine On
RewriteRule ^(.*)$ https://www.mydomain.com/blog/$1 [NC,L,NE,R=302]
RewriteCond %{HTTP_HOST} !^(sub1|sub2)\.myinitialdomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [L,NE,R=302]
Make sure this is first rule in /wordpress/.htaccess file.
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]
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]