| | #1 |
| Warrior Member Registered Member Join Date: 2013
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
|
Hello. I wish to change a category name on my wordpress site. That site is on a subdomain. I wish to change from (eg): sub.example.com/old/ to sub.example.com/new/ I noticed that there is no .htaccess file on the subdomain folder, so I guess I'll have to add some code to the "main domain" .htaccess, right? And may you please tell me wich code should I add? I've search about this question, but I didn't find anything about this particular case (subdomains). Thank you for your time. |
| |
| | #2 |
| HyperActive Warrior War Room Member Join Date: 2014 Location: New Zealand
Posts: 210
Thanks: 25
Thanked 81 Times in 71 Posts
|
Hi KbPI, This should do the trick, if I understand you correctly ![]() RewriteEngine on RewriteCond %{HTTP_HOST} ^sub.example.com [NC] RewriteRule /old/ http://sub.example.com/new/ [L,R=301] Pretty basic redirect - the rule essentially goes like this.. "when requested for /old/, redirect to /new/, but only if HTTP_HOST (the requested host) starts with sub.example.com" Cheers, Michael |
| | |
| |
| The Following User Says Thank You to emptee For This Useful Post: |
| | #3 |
| Warrior Member Registered Member Join Date: 2013
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
|
Hello emptee! Thank you very much for you help ![]() Cheers! Edit: Oops. I have a question, please... Should I add that code to .htaccess from the "main domain folder" (example.com) or should I create a new .htaccess file inside the sub.example.com folder? Thank you again |
| |
| | #4 |
| Bananas are Yellow! Registered Member War Room Member Join Date: 2013 Location: Wyoming, PA, USA
Posts: 1,046
Thanks: 2,549
Thanked 1,600 Times in 928 Posts
Blog Entries: 4 | |
| Put MY voice on YOUR video: AwesomeAmericanAudio.com | |
| |
| The Following User Says Thank You to David Beroff For This Useful Post: |
| | #5 |
| HyperActive Warrior War Room Member Join Date: 2014 Location: New Zealand
Posts: 210
Thanks: 25
Thanked 81 Times in 71 Posts
|
The .htaccess file that needs to be modified.. is whichever one lives in the correct vhost ![]() Eg. if you have two vhosts set up, say... domain.com -> /home/apache/domain.com/public_html sub.domain.com -> /home/apache/sub.domain.com/public_html Then the .htaccess file you'll want to modify would be /home/apache/sub.domain.com/public_html/.htaccess But.. if you're serving both sub.domain.com and domain.com from the same vhost, then whichever .htaccess file is in the root of that vhost is the right one. How do you know which configuration you're running if you don't manage the vhosts yourself? Well - simple - if going to either sub.domain.com or domain.com results in the same website being shown, then you most likely only have one vhost configured for both domains.. otherwise.. you've probably got seperate vhosts. At the end of the day - it doesn't really matter if you put it into the wrong .htaccess file, as it will have no effect at all if it's in the wrong vhost, due to the "but only if HTTP_HOST (the requested host) starts with sub.example.com" condition. Cheers, Michael |
| | |
| |
| The Following User Says Thank You to emptee For This Useful Post: |
| | #6 |
| Warrior Member Registered Member Join Date: 2013
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
|
Thank you emptee! you have been very helpful ![]() Cheers! Edit: It's not working ![]() Well, there was a .htaccess file inside sub.domain folder. Here's what .htaccess looks like before adding that code: # Use PHP5.4 as default AddHandler application/x-httpd-php54 .php # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress Does it matters where put the code you gave me? I've tried on almost every line. Top, bottom, middle. Any ideas, please? Thank you again |
| |
| | #7 |
| HyperActive Warrior War Room Member Join Date: 2014 Location: New Zealand
Posts: 210
Thanks: 25
Thanked 81 Times in 71 Posts
|
Ahh - you're using wordpress! I'd just use a plugin if it were me - there are a ton of redirection plugins that will do what you need.. Alternatively, the code would have to go just after the RewriteBase line.. and it may be overwritten if a plugin rewrites your .htaccess file (Yoast does this, from memory...) Or.. you could put the code at the bottom of the file and make sure /old/ exists within the vhost. Do yourself a favor and use a plugin - it'll be easier to manage in the future.. and unless you're trying to squeeze the last few visitors out of your server, the performance impact will be negligible. Cheers, Michael |
| | |
| |
| | #8 | |
| Active Warrior Join Date: 2014 Location: Bangalore
Posts: 53
Thanks: 0
Thanked 3 Times in 3 Posts
|
Hi, No need to add new .htaccess file as it is already present in the sub-domain Wordpress folder which you have installed. Note : 1) Login to your Cpanel 2) Click on File manager option 3)Click on the option(Show hidden files) showed in pop up dialogue box and proceed. You will find .htaccess file in that | |
| |
|
| Bookmarks |
| Tags |
| 301, htaccess, redirect, subdomain |
| |