I'm trying to redirect...
http://blog.example.org/folder/name-of-page.html
...to....
http://www.example.org/different-name-of-page.html
For my .htaccess file under blog.example.org I've added...
Redirect 301 /folder/name-of-page.html http://www.example.org/different-name-of-page.html
However, when I do this it takes me to http://www.example.org/blog/folder/different-name-of-page.html
For some reason it's auto-populating the /blog/folder/ part instead of taking me to the URL I've suggested.
Any idea on a fix?
It looks like it's interferring with rewrite rules that you have that map subdomains to folders. Use mod_rewrite instead of the Redirect directive.
Before any of your other rules, add:
RewriteCond %{HTTP_HOST} ^blog\.example\.com$ [NC]
RewriteCond %{THE_REQUEST} /folder/name-of-page\.html
RewriteRule ^ http://www.example.org/different-name-of-page.html [L,R]
Related
i need to redirect all request going to any subdomain on domain1.com to domain2.com passing the subdomain part as path, so for example:
sub1.domain1.com -> domain2.com/sub1
this works with my current rewrite rule:
RewriteCond %{HTTP_HOST} ^.+?\.domain1\.com$ [NC]
RewriteRule ^(.*)$ https://domain2.com/$1 [L,R=301]
but when i have a subdomain like the following, it doesn't work:
sub1.sub2.domain1.com -> is redirecting to domain2.com/ without taking the subdomain parts to the path. (domain2.com/sub1.sub2)
how can i get this to work for any combination of subdomain?
I fail to see who any such redirection currently works. The rewriting rule you posted certainly does not do what you describe...
I suggest such an approach to hand over the "subdomain name":
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:(.+)\.)?domain1\.com$ [NC]
RewriteRule ^ https://domain2.com/%1 [L,R=301]
https://sub1.sub2.domain1.com/some/path => https://domain2.com/sub1.sub2
This obviously will ignore whatever path has originally been requested, but that is what you intend, as I understood. If you also want to keep the path and only precede it with the subdomain name, then this variant should point you into the right direction:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:(.+)\.)?domain1\.com$ [NC]
RewriteRule ^/?(.*)$ https://domain2.com/%1/$1 [L,R=301]
https://sub1.sub2.domain1.com/some/path => https://domain2.com/sub1.sub2/some/path
It is a good idea to start out using a 302 redirection and only change that to a 301 once things work as desired. That prevents you from running into caching issues...
I want to redirect example.com/recipes/signup?code=OLD277 to example.com/recipes-user/register How can I achieve it via htacces?
I tried the below code in .htaccess but its not working!
Redirect /recipes/signup?code=OLD277 http://example.com/recipes-user/register
You may use this rule as your topmost rule in site root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} /recipes/signup\?code=OLD277\s [NC]
RewriteRule . /recipes-user/register? [R=301,L,NE]
I am trying to redirect the following (respectively):
http://sub.firstdomain.com/d/(all_files_and_folders)
http://sub.firstdomain.com/d2/(all_files_and_folders)
to
http://sub.seconddomain.com/d/(all_files_and_folders)
http://sub.seconddomain.com/d2/(all_files_and_folders)
There are other files and folders under the first subdomain that I do not want redirected. Previously this was working but now it seems like Go Daddy changed something and what I had is no longer working. Here it is:
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^stats/(.+) /dstats/count.php?statspage=$1 [L,NC,QSA]
RewriteRule ^(.+)\.deb$ /dstats/count.php?file=$1.deb [L,NC,QSA]
RewriteCond %{HTTP_HOST} ^sub\.
RewriteRule ^(d2?)/(.*)$ http://sub.seconddomain.com/$1/$2 [L,R=301]
You can ignore the RewriteRule. It is working fine. I wanted to make sure I included the entire .htaccess file just in case. My issue is with RewriteCond it seems.
The following should work:
RewriteEngine On
Redirect 301 /d/ http://sub.seconddomain.com/d/
Redirect 301 /d2/ http://sub.seconddomain.com/d2/
The above should only redirect anything in the /d/ and /d2/ folder of the sub subdomain.
EDIT: Second try
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub1\.
RewriteRule ^(d2?)/(.*)$ http://sub2.mydomain.com/$1/$2 [L,R=301]
I have used the following to rewrite urls on my website
RewriteRule writers/(.*)/ writer-pages.php?page_name=$1
RewriteRule writers/(.*) writer-pages.php?page_name=$1
which works fine, but I have old pages that have an extension /writers/name-here.php and the rewrite above removes the .php how can I redirect the old .php to the the urls without the extension.
Another problem is I don't want redirect all .php pages
Any idea how I can do this. Any help would be much appreciated
RewriteRule writers/(.*).php writers/$1/
you can test your rewrite rules at rewrite-rule-tester
Your 2 rules can be combined into one.
You need an additional rule.
Here is the code:
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /+writer-pages\.php\?page_name=([^\s&]+) [NC]
RewriteRule ^ writers/%1? [R=302,L]
# your original rule
RewriteRule writers/([^/]*)/?$ writer-pages.php?page_name=$1 [L,QSA]
I am needing to forward a whole domain minus one folder and it's contents.
http://www.domain.com/folder_I_need/content_I_need.stuff
The rest of the site needs to forward.
Here is what I've tried:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/folder_I_need/$
Redirect 301 / http://www.new_domain.org/
The RewriteCond directive is part of mod_rewrite and Redirect directive part of mod_alias, they don't work in conjunction with each other. You also probably don't want the $ at the end of your condition's pattern. Try:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/folder_I_need/
RewriteRule ^(.*)$ http://www.new_domain.org/$1 [L,R=301]