www.webdeveloper.com
Results 1 to 8 of 8

Thread: Help with htaccess

  1. #1
    Join Date
    Jul 2014
    Posts
    6

    Help with htaccess

    Hi

    I am fairly new to htaccess and have run in to a few problems. I have just provided my client with a new website which is located on the same domain as his old one. i have submitted his new sitemap to Google and have noticed that his old urls as still showing up and i am getting messages in webmaster to back this up.

    I have had a play around tonight and i managed to get one redirect working. So i tried some others and i came unstuck.

    Here is my htaccess

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    # Permanent URL redirect - generated by www.rapidtables.com
    Redirect 301 /privacy_policy.php http://www.brianthebrushuk.com/
    Redirect 301 /gallery.php?gallery=1 http://www.brianthebrushuk.com/
    Redirect 301 /gallery.php?gallery=2 http://www.brianthebrushuk.com/
    Redirect 301 /gallery.php?gallery=3 http://www.brianthebrushuk.com/
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress

    The one in red works, the others below don't :-(

    I actually want to redirect the urls to other specific pages within the new site, but i thought if i could test it working by using the home page, i could then add the rest of the new urls.

    Hopefully i have explained myself. I appreciate anyones help with this

    Thanks

  2. #2
    Join Date
    Jul 2014
    Location
    Rostock
    Posts
    15
    Code:
    # 301 Redirect 1
    RewriteCond %{QUERY_STRING}  ^$
    RewriteRule ^privacy_policy\.php$ http://www.brianthebrushuk.com/? [R=301,NE,NC,L]
    
    # 301 Redirect 2
    RewriteCond %{QUERY_STRING}  ^gallery=1$ [NC]
    RewriteRule ^gallery\.php$ http://www.brianthebrushuk.com/? [R=301,NE,NC,L]
    
    # 301 Redirect 3
    RewriteCond %{QUERY_STRING}  ^gallery=2$ [NC]
    RewriteRule ^gallery\.php$ http://www.brianthebrushuk.com/? [R=301,NE,NC,L]
    
    # 301 Redirect 4
    RewriteCond %{QUERY_STRING}  ^gallery=3$ [NC]
    RewriteRule ^gallery\.php$ http://www.brianthebrushuk.com/? [R=301,NE,NC,L]
    Check out this tool

    https://websiteadvantage.com.au/HtAc...rect-Generator

  3. #3
    Join Date
    Jul 2014
    Posts
    6
    Hi Thanks for the reply. I know htaccess can be tricky but when i add these rules it stops the site from loading.

    Can someone reply and show my exactly where these rules would feature in a standard htaccess file.

    The file i am currently using that works is

    # 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
    Thanks

  4. #4
    Join Date
    Jul 2014
    Posts
    6
    Hi

    Is anyone able to assist me with this problem.

    Many thanks

  5. #5
    Join Date
    Jul 2014
    Location
    Adelaide, Australia
    Posts
    2
    It's probably about the order of your code. First a tip:

    Do not place any custom code in any one elses section. It may/will get removed when things update.

    A section is defined by

    # BEGIN <My section name>
    stuff just for me in my section
    # END<My section name>

    Either place your code outside a section or create your own section with your own name

    Next to your problem.

    @Michael unfortunately did not provide the full code that my tool creates. He missed out these lines:

    # Needed before any rewriting
    RewriteEngine On

    ### Built using the .htaccess 301 Redirect Generator from Web Site Advantage
    ### https://websiteadvantage.com.au/HtAc...rect-Generator
    ### Place after 'RewriteEngine On' and before any CMS specific rewrite rules

    Most are comment but they are there to help you get things right. Before any RewriteRule you need this command:

    RewriteEngine On

    And you need to place your redirects before any commands that take over, like the WordPress block

  6. #6
    Join Date
    Jul 2014
    Posts
    6
    Hi

    I have followed your instructions and this is what i have so far

    # 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>

    # 301 Redirect 1
    RewriteEngine On
    # 301 Redirect 2
    RewriteCond %{QUERY_STRING} ^gallery=1$ [NC]
    RewriteRule ^gallery\.php$ http://www.brianthebrushuk.com/tradi...painted-signs/ [R=301,NE,NC,L]

    At the minute the site is still working but the redirect isnt

    Any ideas ?

    Thanks

  7. #7
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,519
    My knowledge of rewrite rules is limited but isn't 1$ meant to be $1

    RewriteCond %{QUERY_STRING} ^gallery=1$ [NC]

    RewriteCond %{QUERY_STRING} ^gallery=$1 [NC]
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  8. #8
    Join Date
    Jul 2014
    Location
    Adelaide, Australia
    Posts
    2
    Quote Originally Posted by \\.\ View Post
    My knowledge of rewrite rules is limited but isn't 1$ meant to be $1

    RewriteCond %{QUERY_STRING} ^gallery=1$ [NC]

    RewriteCond %{QUERY_STRING} ^gallery=$1 [NC]
    In this case it's correct. The $ signifies the end of a line and not a capture group.

    The reason it does not work is probably as I stated before:

    And you need to place your redirects before any commands that take over, like the WordPress block

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles