• Resolved sarahmghart

    (@sarahmghart)


    I just moved my site from sarahhart.ca/boutique to sarahhart.ca/blog is there a way with php to redirect a specific url to my new site. So for example if someone types in sarahhart.ca/boutique/quiz it automatically goes to sarahhart.ca/blog/quiz

    Thanks!

    Sarah

Viewing 5 replies - 1 through 5 (of 5 total)
  • C W (VYSO)

    (@cyril-washbrook)

    I’m slightly fuzzy on what precisely you need (feel free to clarify), but if you’ve moved your entire site to a new directory, you may wish to set a rewrite rule in the .htaccess file via FTP. There will probably already be a .htaccess file in the root directory.

    The following steps will redirect any URL beginning with sarahhart.ca/boutique to the equivalent URL beginning with sarahhart.ca/blog. (Again, if this isn’t what you are looking for, feel free to say.)

    Step 1: Insert the following new lines (put them at the start of the file to make sure they take priority):

    RewriteEngine on
    RewriteRule ^/?boutique/(.*)$ /blog/$1 [R,NC,L]

    Just note that browser caching means that you may not see the redirection immediately.

    Step 2: Once you have verified that this is working as you intended, change the above lines to this:

    RewriteEngine on
    RewriteRule ^/?boutique/(.*)$ /blog/$1 [R=301,NC,L]

    The additional =301 will instruct browsers and search engines that your content has moved permanently to the new location.

    (In principle you can actually skip straight to step 2, but I recommend doing it in two steps, because it can be a pain to undo 301 redirects if you make a mistake or you want to change something.)

    If you just want to redirect then you can use .htaccess to do that.

    for example:
    Redirect 301 /oldstuff.html https://www.yourwebsite.com/newstuff.html

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    sunil333’s directions aren’t wrong, but C W’s are the ones you want to follow here ??

    Thread Starter sarahmghart

    (@sarahmghart)

    Thank you so much!!

    I have a few lines in my .htaccess file already, can you let me know where I should put your code C W?

    DirectoryIndex index.php index.html Home.html
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]
    
    # 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

    C W (VYSO)

    (@cyril-washbrook)

    It’s probably best to put the code at the top of the .htaccess file, on new lines. This will ensure that it takes priority over any conflicting rule.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘redirect / forwarding to new domain’ is closed to new replies.