Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: .htaccess help

  1. #1
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts

    Question .htaccess help

    I am trying to make my search engine links more search engine friendly and I have tried so many different thing with .htaccess but cannot quite get it to work.
    here is what my url looks like
    http://domain.com/search.php?query=keyword&search=1

    here is what I have been trying. This is the best results I have gotten so far.

    PHP Code:
    Options  -Indexes
    Options 
    +FollowSymLinks

    RewriteEngine on
    RewriteCond 
    %{QUERY_STRING} ^query=(.*)&search=1

    RewriteRule ^search.php$ /search/%1/? [R=301,L]

    RewriteRule ^search/(.*) search.php?query=$1&search=[L
    when i do a search for the word keyword it looks like this http://domain.com/search/keyword/ but it doesn't show anything. i can see that it is picking up the keyword but i dont quite understand why this doesn't work. Can anyone help?

  • #2
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    I think what is going on is &search=1 is not picking up. I cant seem to get it to grab that part of the link or something.

  • #3
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Any help is appreciated. I kep trying different stuff and that same code is where I always end up. is there something I can do so that I dont have to manually change the php code that creates the urls? mod_rewrite just does not want to work right with this.

  • #4
    New to the CF scene
    Join Date
    Oct 2010
    Location
    Romania
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    RewriteRule ^search.php$ /search/%1/? [R=301,L]

    RewriteRule ^search/(.*) search.php?query=$1&search=1 [L]

    are making a loop
    search.php rewrites to /search/* which rewrites to search.php which rewrites to /search/* etc
    I would introduce a ReWriteCond %{REQUEST_URI} !^search\.php$ or something like that.
    Actually i think you can't really filter the search.php because that will skip the whole rewrite.
    Maybe something in the vicinity of

    RewriteRule ^search/(.*)(/)?$ search.php?query=$1&search=1 [L]
    ReWriteCond %{REQUEST_URI} ^search\.php$
    RewriteRule ^search.php?query=(.+)&search=1$ http://www.url.com/search/%1/? [R=301,L]

    I have not tested this code, it's written from the top of my head..
    I hope it helps you.. somehow
    I like to play jocuri cu masini and jocuri barbie

  • #5
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ax8l View Post

    RewriteRule ^search.php$ /search/%1/? [R=301,L]

    RewriteRule ^search/(.*) search.php?query=$1&search=1 [L]

    are making a loop
    search.php rewrites to /search/* which rewrites to search.php which rewrites to /search/* etc
    I would introduce a ReWriteCond %{REQUEST_URI} !^search\.php$ or something like that.
    Actually i think you can't really filter the search.php because that will skip the whole rewrite.
    Maybe something in the vicinity of

    RewriteRule ^search/(.*)(/)?$ search.php?query=$1&search=1 [L]
    ReWriteCond %{REQUEST_URI} ^search\.php$
    RewriteRule ^search.php?query=(.+)&search=1$ http://www.url.com/search/%1/? [R=301,L]

    I have not tested this code, it's written from the top of my head..
    I hope it helps you.. somehow
    no that doesnt work either, even after i messed with it. I am still trying to make something work. I made a mod_write log so i know what is going on each query but i am still having trouble.


  •  

    Posting Permissions

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