Forum Moderators: phranque
NOW, MY SE FRIENDLY URL IS
mydomain.com/folder/term+term.html
BUT, I WANT TO USE
mydomain.com/folder/term-term.html
RewriteEngine on
RewriteRule ^folder/([a-zA-Z0-9\-\+\&\%\ ]+)\.html$ folder/search.php?searchterm=$1
RewriteRule ^folder/([a-zA-Z0-9\-\+\&\%\ ]+)/([a-zA-Z0-9\-\+\&\%\ ]+)/$ folder/search.php?offset=$1&searchterm=$2
RewriteRule ^folder/([a-zA-Z0-9\-\+\&\%\ ]+)/([a-zA-Z0-9\-\+\&\%\ ]+)/([a-zA-Z0-9\-\+\&\%\ ]+)$ folder/search.php?offset=$1&searchterm=$2&language=$3
Then use mod_rewrite to change those URLs back, if necessary, to call your script.
More info here [webmasterworld.com].
Jim
Maybe you misunderstand, or I'm miscommunicating. Don't worry about my links in pages etc. It's a new site, new content. So, as I create it, I want the mod rewrite to handle a link like this.
Current: MySite/MyFolder/term+term.html = works fine now
Desired: MySite/MyFolder/term-term.html = want this to work
Can someone look at the code and tell me how I can do this with the mod rewrite? Or, confirm it isn't possible, I prefer to fix this in Mod rewrite if at all possible. I am a total beginner with mod rewite, I barely know where it goes and what it can do. It may be simple (i think) but I need help with this "+"
many thanks in advance.
Based on those facts, what is the URL published on your page, and how do you want to change the file association of that URL?
I see rules that map URLs like mydomain.com/folder/term/term.html to the file /folder/search.php?offset=$1&searchterm=$2
where mydomain.com/folder/term/term.html is the URL and /folder/search.php?offset=$1&searchterm=$2 is the associated file-plus-query-string.
I do not see any rules that map URLs with "+" or "-" as parameter *delimiters*, and maybe that's where I'm falling off this train. If the example needs adjustment to be consistent with the discussion, please do adjust it.
BTW, you can write ([a-zA-Z0-9\-\+\&\%\ ]+) as ([a-z0-9&+\-\%\ ]+) by using the [NC] flag on RewriteRule:
[NC] makes the compare case-insensitive, saving some processor time, and not all of those characters need to be escaped within a regex group.
Jim
Yes, Great explanation. I'm with you. The SE friendly URLs I'm talking about will be what I manually use building pages or typing in browsers. It all works exactly as I like, EXCEPT where I must pass a multi-word search term. I am waiting to build any links till I get them working exactly like I want. If I use a multi-word search term, I want to pass that in my browser with a "-" not a "+".
>> I see rules that map URLs like
>> mydomain.com/folder/term/term.html to the file
>> /folder/search.php?offset=$1&searchterm=$2
Well Yes, very close it maps: "mydomain.com/folder/big+hooters.html"
<not>
"mydomain.com/folder/big/hooters.html"
Its just that where I map that variable "searchterm", in a case like above where is it a multi-word search term, like "big+hooters" I want to use the link in my browser URL:
mydomain.com/folder/big-hooters.html
Currently, If it's a single word search term, like "hooters" it currently works if I use:
mydomain.com/folder/hooters.html
But, currently if I use a multi-word search term in the URL, I MUST supply the link like this to the browser, with a "+"
mydomain.com/folder/big+hooters.html
But I Want: mydomain.com/folder/big-hooters.html
My PHP search scripting wants that as a "+" when it processes that multi-word search term, not a "-". I am trying to modify my .htaccess to handle that.
>> BTW, you can write ([a-zA-Z0-9\-\+\&\%\ ]+) as
>> ([a-z0-9&+\-\%\ ]+) by using the [NC] flag on
>> RewriteRule:
>> [NC] makes the compare case-insensitive, saving some
>> processor time, and not all of those characters need
>> to be escaped within a regex group.
Damn, I wish i understood that better. I'm going to try to figure that out. I think I understand what you are saying but will have to figure out what to do to employ it. Jim, thank you so much for your time. I am trying to communicate and learn this stuff and I appreciate you taking the time to help. I think I'm learning a little.
That should give you test-test. Now the problem I'm having is with my rewrite getting screwed up because of the multiple dashes in the URL. :(