Forum Moderators: phranque
eg
rewriteRule ^subcat1/subcat25/$ /search.php?categorry-25
when i go through the directory structure firstly through homepage. I click on subcat1, and it displays other subcatergorys.
But the URl i observe in this directory till /search.php?categorry-25,this because it is run on the fly dynamically with phP, how can i make it appear subcat1/subcat25 instead?
it works fine if i type in directly
www.domain/subcat1/subcat25/
that goes to /search.php?categorry-25
however when i do a search engine look up, the catergorys appear as /search.php?categorry-25?
Is there a way so that if it senses /search.php?categorry-25 anywhere it changes it refreshes or changes it straight away to subcat1/subcat25 without the user knowing.
i hope you can help
rewriteRule ^subcat1/subcat25/$ /search.php?categorry-25
#First make sure you don't already have the new URLs
RewriteCond %{REQUEST_URI} !^/subcat1/(.*)$
#Then turn any remaining old URLs into new ones via a 301 redirect
RewriteRule ^/search.php?category-([0-9]+)$ /subcat1/subcat$1 [R=301,L]#Finally turn newm URLs internally back into the old ones:
RewriteRule ^/subcat1/subcat([0-9]+)$ /search.php?category-$1 [L]
This should change all old addresses in the browser window and slowly cause Google to pick up th enew URLs, while internally the system works as usual.
SN
eg, on home page
16 directorys
all having /search.php?catergory1 or 2 or 3 or 4 to 16
can i make all those change to corresponding /catergory/ on the homepage w\so it loads up without ppl realising.?
RewriteCond %{REQUEST_URI}!^/subcat1/(.*)$
is this the main catergory
or subcatergory?
do catergory1/subcat1/
do backslashes make a difference
am using .htaccess
im doing this through php, what could be wrong.
COuld you explain a bit clearer what could be wrong?
Now if u go over "Business" it with the mouse you see the url at the bottom of explorer as /search/search.php?search=cat&category=1
now i would like this mouseover to appear as /business/ and /business/economics/ etc.
Then when i click at "business", it shows /search/search.php?search=cat&category=1 in the browser on the new page.
I want this too appear as /business/
On this same page, there are subcatergorys listed which are econimics and finance. These catergorys when u go over the mouse are shown as /search/search.php?search=cat&category=2 and /search/search.php?search=cat&category=3
I want these to also appear as /business/economics/
I hope its a little clearer what i want to do, can u help?
its a off the shelf directory software i bought, so i can do whatever really cos i got it hosted remotely.
but i have a search facility and when it comes up with results i have the catergories listed for the results, i want those catergorys to give old results to not be inconsistent.
So ye what could i do?
rewriteRule ^subcat1/subcat25/$ /search.php?categorry-25
that works fine.
what about these, how do i know these are working fine?
#First make sure you don't already have the new URLs RewriteCond %{REQUEST_URI}!^/subcat1/(.*)$ #Then turn any remaining old URLs into new ones via a 301 redirect RewriteRule ^/search.php?category-([0-9]+)$ /subcat1/subcat$1 [R=301,L] #Finally turn newm URLs internally back into the old ones: RewriteRule ^/subcat1/subcat([0-9]+)$ /search.php?category-$1 [L]
I'm off for the day to do other things, but you need to know a couple of things. First, in this rule:
RewriteRule ^/search.php?category-([0-9]+)$ /subcat1/subcat$1 [R=301,L]
the leading slash in the pattern will only match if this code is in httpd.conf. The rule won't work in .htaccess.
Second, if you want an external redirect - one that changes the URL in the visitor's browser and causes robots to note a change for their search index, then you must use the [R] flag, and you should use a full URL:
RewriteRule ^search.php?category-([0-9]+)$ http://www.yourdomain.com/dir/subcat1/subcat$1 [R=301,L]
In all cases, the [L] flag stops further processing for the request-in-progress, which reduces the chances for an infinite loop and saves processing time. It is most likely that this is what you want to do. I note this only in case you want one request to activate multiple rewriterules in sequence, with each rule changing the URL one step at a time.
HTH,
Jim
i have two rules wrriten up
Options +FollowSymLinks
rewriteEngine on
rewriteRule ^search/sample.php?search=cat&category=31([0-9]+)$ /search/engineering$1 [R=301,L]
rewriteRule ^engineering/$ /search/hyperseek-sample.php?search=cat&category=31
The 2nd rule works why doesnt the first?
the url i want to show on the user browser should be
domain.com/engineering instead of domain.com/search/sample.php?....
should it be
rewriteRule ^www.domain/search/sample.php?search=cat&category=31([0-9]+)$ /search/engineering$1 [R=301,L]
?
RewriteCond %{QUERY_STRING} ^search=cat&category=31([0-9]+)$
RewriteRule ^search/sample\.php$ http://www.domain.com/search/engineering%1 [R=301,L]
here it is the code in the search directory for .htaccess
Options +FollowSymLinks
rewriteEngine on
RewriteCond %{QUERY_STRING} ^search=cat&category=31([0-9]+)$
RewriteRule ^search/sample\.php$ [domain.com...] [R=301,L]
rewriteRule ^engineering/$ /search/sample.php?search=cat&category=31
when i type i want it to go from
www.domain/search/sample.php?search=cat&category=31
this is on my homepage to go to when i click it to go to
www.domain/engineering
help anyone please
If you want to put this code in subdirectory "search", then "search" cannot be included in the 1st RewriteRule, as it will have been stripped off by then:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^search=cat&category=31([0-9]+)$
RewriteRule ^sample\.php$ http://www.domain.com/search/engineering%1 [R=301,L]
RewriteRule ^engineering/$ /search/sample.php?search=cat&category=31
I encourage you to read the documentation and experiment with this until you get comfortable with it.
Ref: Introduction to mod_rewrite [webmasterworld.com]
HTH,
Jim
i have tried it seriously over 50 times, and it only brings up
www.domain/search/sample.php?search=cat&category=31
doesnt change it at all
creating the directory is no problem just the first rule part seems to do nothing at all
is the order of the rules correct
?
For the root directory:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^search=cat&category=31([0-9]+)$
RewriteRule ^search/sample\.php$ http://www.domain.com/search/engineering%1 [R=301,L]
RewriteRule ^engineering/$ /search/sample.php?search=cat&category=31 [L]
RewriteCond %{QUERY_STRING} ^search=cat&category=31([0-9]+)$
RewriteRule ^search/sample\.php$ http://www.domain.com/search/engineering%1 [R=301,L]
It strikes me that perhaps the rule you wrote with the categories was not what you wanted. Do your categories run from 310-319, or from 31-39? If the latter, then you need:
RewriteCond %{QUERY_STRING} ^search=cat&category=(3[1-9]+)$
The second rule unconditionally and transparently redirects from "www.domain.com/engineering/" to "www.domain.com/search/sample.php?search=cat&category=31"
It will not redirect if the trailing slash is missing.
Jim