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
Related
So i have a htaccess rewrite that makes a query string to a path like so..
RewriteRule ^page/(.*)$ page.php?query=$1
This works fine and using the above i can access the page via both page.php?query= and /page/query/ but how can i make it so that if the page is accessed by the page.php?query= method, it automatically redirects to the path version?
I've tried the following but i don't think i wrote it correctly...
RewriteCond %{HTTP_HOST} ^www\.webaddress\.com\/page\.php\?query\=$
RewriteRule ^(.*)$ http://www.webaddress.com/page/$1 [R=301,L]
Any help to fix this would be appreciated. Thanks.
You can use the following
RewriteEngine On
#url redirection from old url to the new one
#redirect /page.php?query=foo to /page/foo
RewriteCond %{THE_REQUEST} /page.php\?query=([^\s]+) [NC]
RewriteRule ^.+$ /page/%1? [L,R]
#url rewiring from new url to the old one
# rewrite /page/foo to /page.php?query=foo
RewriteRule ^page/(.*)$ page.php?query=$1 [L]
Try it before your internal rewrite rule.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.+)\.php
RewriteCond %{QUERY_STRING} ^(.+)\=(.+)
RewriteRule ^ http://%{HTTP_HOST}/%1/%2/%3? [R=301]
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 am trying to redirect myname.mydomain.com to www.mydomain.com/search/?q=myname
I have tried:
ReWriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain.com$
RewriteRule ^(.*)$ http://www.mydomain.com/search/?q=$1 [QSA,L]
The redirect works but sends me to www.mydomain.com/search/?q= it does not include the search string (ie. subdomain)
What am I doing wrong?
Thanks
You need to use %1 instead since you are capturing group in RewriteCond:
ReWriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain.com$
RewriteRule ^(.*)$ http://www.mydomain.com/search/?q=%1 [QSA,L]
Currently I have this rewrite rule in place and it works great:
RewriteRule ^search/([^/]+)/? search.php?term=$1 [NC,QSA]
When I go to mysite.com/search/foo it takes me to the proper search page for foo. what I am looking to do is make the opposite work as well so that if I visit mysite.com/search.php?term=foo I will be taken to mysite.com/search/foo. I think I need a 301 redirect somewhere but I'm not sure how to do it without creating an infinite loop and the other posts I've read so far haven't been much help.
Try:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /search\.php\?term=([^&]+)
RewriteRule ^search\.php$ /search/%1/? [L,R=301]
or (if you place these after the rule that you already have
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{QUERY_STRING} ^term=([^&]+)$
RewriteRule ^search\.php$ /search/%1/? [L,R=301]
Try this:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+mysite.com/search.php?term=foo [NC]
RewriteRule ^ mysite.com/search/foo [L,R=301]
Add the R flag to your RewriteRule:
RewriteRule ^search/([^/]+)/? search.php?term=$1 [NC,QSA,R=301]
I previously asked this question and the answer did not seem to work as required - it also required an addition.
Users are provided with unique URL's, ie: exampleurl.com/AQ4ILB9
AQ4ILB9 being the referral code
I would like that URL above (or any referral URL) to display the contents of index.php (htaccess redirect?)
I would like the non-www and www version of exampleurl.com, including example.com/index.php to be redirected to the top level in this format: http://www.exampleurl.com/
I would like for example: $_GET['_url'] to hold the referral id (ie: AQ4ILB9) in index.php
How can I go about the above 3 all using htaccess?
Thanks!
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9]+)$ /index.php?_url=$1 [NC,L,QSA]
The first part is a 301 redirect to add www.
The second part will rewrite what you want, but not for existing files/directories.
Q) 1 & 3:
RewriteRule (.*) index.php?url=$1 [L,P]
Q) 2:
RewriteCond %{HTTP_HOST} ^exampleurl.com
RewriteRule (.*) http://www.exampleurl.com/$1 [R=301,L]
RewriteRule ^/([A-Z0-9]+)$ index.php?_url=$1
Replace example.com with your domain and put this in your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule (.*) /index.php?_url=$1 [L]
Should do the trick! You may not need the RewriteEngine On line if it's already there.