1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

FAQ: mod_rewrite, 301 redirects, and optimizing Apache.

Discussion in 'Apache' started by Nintendo, Jul 30, 2005.

  1. RaZoRLeGaCy

    RaZoRLeGaCy Well-Known Member

    Messages:
    189
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #881
    Hello,

    My problem is that when I go to http:\/\/untoldscifi.com it pulls up the other site that I have on the server as well. The http:\/\/www.untoldscifi.com works well.

    I don't want to get banned so you need to manually enter the urls to test.

    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.untoldscifi\.com$ [NC]
    RewriteRule ^(.*)$ http://untoldscifi.com/$1 [L,R=301]

    Any help on this is greatly appreciated.
    SEMrush
     
    RaZoRLeGaCy, Sep 11, 2009 IP
    SEMrush
  2. lunarpages

    lunarpages Peon

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #882
    do you have resolved it? may you provide your .htaccess files? thx

     
    lunarpages, Sep 16, 2009 IP
  3. Tigerboy

    Tigerboy Member

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #883
    But if i can't use .htaccess what can i do? I read that i can use a php redirection but i can't understand where to place the php code. How to redirect the entire webiste from non www to www?
    Thanks in advance!
     
    Tigerboy, Oct 7, 2009 IP
  4. remember123

    remember123 Peon

    Messages:
    620
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #884
    Hi ..can any one suggest me best setting for serving static content ?
    thanks
     
    remember123, Oct 23, 2009 IP
  5. saqistation

    saqistation Peon

    Messages:
    328
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #885
    Thanks 4 sharing ur knowledge.
     
    saqistation, Nov 12, 2009 IP
  6. pachel

    pachel Active Member

    Messages:
    99
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #886
    ServerAlias *.domain.com
    Options +FollowSymLinks
    Options +Indexes
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^([^.]+).domain.com$
    RewriteCond %{HTTP_HOST} !^(www|includes|images| )$
    RewriteCond http://www.domain.com/gebruikers/$1 -d
    RewriteCond %{REQUEST_FILENAME} !^http://www.domain.com/gebruikers/
    RewriteRule ^(.*)$ /gebruikers/$1 [L]

    This is a try to make all directorys in gebruikers a subdomain but it doesn't work.
    and when the directory doesn't excist the homepage can someone help?
     
    pachel, Nov 19, 2009 IP
  7. BlueEew

    BlueEew Well-Known Member

    Messages:
    2,435
    Likes Received:
    79
    Best Answers:
    1
    Trophy Points:
    150
    #887
    How would I do this:

    /page-one.php

    into /page/one/

    I cannot seem to work this out?
     
    BlueEew, Nov 26, 2009 IP
  8. Kim_Miller

    Kim_Miller Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #888
    For BlueEew

    If the php files are like "page-one.php" "page-two.php" "page-google.php"
    (the word "page" always remains the same)

    then try this..

    
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^/page/(.*)/$ page-$1.php [L]
    
    Code (markup):
     
    Kim_Miller, Dec 5, 2009 IP
  9. BlueEew

    BlueEew Well-Known Member

    Messages:
    2,435
    Likes Received:
    79
    Best Answers:
    1
    Trophy Points:
    150
    #889
    I found a way to do it now. :) Thanks for sharing this also, it will help as it's different to the way I do it.
     
    BlueEew, Dec 5, 2009 IP
  10. Kim_Miller

    Kim_Miller Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #890
    No problems. May I know your way (just learning)
     
    Kim_Miller, Dec 5, 2009 IP
  11. BlueEew

    BlueEew Well-Known Member

    Messages:
    2,435
    Likes Received:
    79
    Best Answers:
    1
    Trophy Points:
    150
    #891
    I am currently using two methods for one website to create two different URLs.

    Here are the following:

    # Force search engines to use www.domain.com
    RewriteCond %{HTTP_HOST} !^www\.domain\.com$
    RewriteRule ^(.*) http://www.domain.com/$1 [R=301,L]


    # Specify search friendly URLs
    RewriteRule ^category/subject/page-name/?$ /category-subject-page-name.php [L]

    The above to create URLs with more then one / in them, then the following:

    RewriteRule ^page-name/?$ /page-name.php

    The above to take the .php anf make it a pretty URL.

    Remember to always add "/?$" without the quote to the end of all pretty URLs. This will make the page work if someone enters a / or not on the end of a web-page URL for example:

    www.domain.com/page/
    www.domain.com/page

    Both will work as long as it as "/?$" on the rewrite.

    Also the part I have bolded will also make your domain redirect to www. even if you don't add the www. when entering URL. Take the www. off this part to make it just http://.
     
    BlueEew, Dec 6, 2009 IP
  12. nas80

    nas80 Greenhorn

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #892
    Dear Friends,

    How to change this URL:
    detail.php?title=Super Duper Cupcakes: Kids' Creations from the Cupcake Caboose&item=1402721749

    into:
    Super Duper Cupcakes: Kids' Creations from the Cupcake Caboose-dp-1402721749

    My RewriteRule:
    RewriteRule ([^/]+)-dp-([A-Z0-9]+)$ detail.php?item=$2&title=$1 [NC,L]

    The rule works well if the title doesn't have colon ":". But, it fails when there is a colon ":" in the title and returns 403 Forbidden Page.

    I've tried to remove the colon in the title using php so that the requested url look like this :
    Super Duper Cupcakes Kids' Creations from the Cupcake Caboose-dp-1402721749
    but, it still doesn't work. If I change the : to / it works but my page messed up..

    How do I solve this problem ?
     
    Last edited: Jan 1, 2010
    nas80, Jan 1, 2010 IP
  13. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #893
    You wanna get it so it's like

    Super-Duper-Cupcakes-Kids-Creations-from-the-Cupcake-Caboose-dp-1402721749

    no spaces or special characters. To get the URL looking nice, use something like...

    $line['title2'] = trim(preg_replace('/[^\w\d]+/', ' ', $line['title']));
    $line['title2'] = str_replace(' ', '-', $line['title2']);

    First line get's rid of all special characters. Second line changes spaces to -.
     
    Nintendo, Jan 6, 2010 IP
  14. bigjimmy

    bigjimmy Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #894
    Hi all, I am new to mod rewrite,
    I know that it can rewrite the url to a SEF url.
    but do I need to manually change the links?

    for example, my website is:
    http://www.ciel.com.hk/diamond.php

    here, user can search diamond base on some criteria, if i want to use the new rewrite url, how should i go about it? and for the list of items, how do i change the link of it?
    so instead of linking to:/diamond_detail.php?serial=CD1000288
    i want it to link to: /diamond/CD1000288.htm

    manually? does mod rewrite does it?
    i know i can rewrite the url so that the latter links to the previous one if i type it in the url, but i can't figure out HOW to get there automatically.

    Thanks for the help in advance
     
    bigjimmy, Jan 26, 2010 IP
  15. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #895
    A .php file won't even know you have a .htaccess file! All mod_rewrite does is makes the static URL work. You still have to change the link code.
     
    Nintendo, Jan 27, 2010 IP
  16. kittuk

    kittuk Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #896
    kittuk, Jan 28, 2010 IP
  17. dan101

    dan101 Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #897
    Hi,

    I have this page

    mydomain.com/search/?=[B]something[/B]
    and I want to redirect to 
    mydomain.com/search/[B]something[/B]
    having [B]RewriteRule search/(.*) /search.php?words=$1[/B] [L,QSA]
    Code (markup):
    Or just

    mydomain.com/search/?=[B]something[/B] to get the /search.php?words=[B]something [/B]
    Code (markup):
     
    dan101, Feb 19, 2010 IP
  18. Danielz

    Danielz Peon

    Messages:
    115
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
  19. KlearConcepts

    KlearConcepts Peon

    Messages:
    349
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
  20. Johnburk

    Johnburk Peon

    Messages:
    777
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #900
    Last edited: Aug 11, 2010
    Johnburk, Aug 11, 2010 IP