Forum Moderators: phranque
[mysite.com...]
to [mysite.com...]
basically i can't figure out how to do that..
anyone can help me here?
Thanks
Deep
Welcome to WebmasterWorld!
The following code demonstrates replacing "¦" in the query string with "-" in the URL, but may not be exactly what you need, because you need to decide whether you want an external redirect or an internal rewrite, whether you want to put the code in httpd.conf or in .htaccess, and whether you actually want to redirect from a dynamic URL to a static URL (it is more usual to rewrite from a static URL to a dynamic one, but that's another subject).
RewriteCond %{QUERY_STRING} cat=([0-9]+)\¦([0-9]+)\¦([0-9]+)&name=([a-z]+)
RewriteRule index\.php$ http://www.example.com/%1-%2-%3-%4.html? [R=301,L]
Jim
btw i am gonna add it in httpd.conf becasue effect i heard that it is much faster than adding .htaccess file..
and one more thing..
in your reply you wrote
RewriteRule index\.php$ [example.com...] [R=301,L]
but for other rewrite rules i have been writing like this..
RewriteRule NewURL $ OldURL
and can you also tell me what will be the effect of R=301 here? 301 is for permenant redirect right?
so does that mean if google or any bot visits the url with query string then it will be redirect to new one and they will take it (redirect) as..url is permenantly moved to new one?
please correct me if i am wrong..
Regards
Deep
i had used this simple code before which didnt have the whole url in the rewrite rule..
RewriteRule /test/(.*)/(.*)/$ /folder1/folder2/index.php?cat=$1&name=$2 so output for above code will be
[mysite.com...]
so i applied same login with your code also..i.e changed it to foll
RewriteCond %{QUERY_STRING} cat=([0-9]+)\¦([0-9]+)\¦([0-9]+)&name=([a-z]+)
RewriteRule /folder1/folder2/index\.php$ /test/%1-%2-%3-%4.html? [R=301,L] this also didnt work so i did like this...
RewriteCond %{QUERY_STRING} cat=([0-9]+)\¦([0-9]+)\¦([0-9]+)&name=([a-z]+)
RewriteRule /test/%1-%2-%3-%4\.html$ /folder1/folder2/index\.php [R=301,L] but again no luck..
let me know if i did anything wrong in above code..i am pretty new to this mod_rewrite thing but it seems to be real interesting to me..
thanks for the help
Deep
I would strongly suggest that you read the mod_rewrite documentation [webmasterworld.com], because that is not how mod_rewrite works.
The documented syntax is:
RewriteRule OldURLpattern Substitution
Where substitution is the new URL.
Perhaps it is just your terminology or expectations that are off-track here; Mod_rewrite rewrites URLs received by your server from client browsers and spiders to new URLs before any content is served or any scripts are run on your server.
Therefore, if you wish to use static links on your pages and convert those to dynamic links for use by your script inside the server, your pages must contain static links. Mod_rewrite cannot affect the way that pages are displayed, it can only affect the way that requests for URLs are handled when they are received.
If you pages contain links in the form:
[mysite.com...]
then those are the links that browsers will use. If you want those URLs to be translated into dynamic links in the form:
[mysite.com...]
then that is the exact opposite of what you asked for in your first message.
It is also a simpler case to code:
ReriteRule /([^-]+)-([^-]+)-([^-]+)-([^.]+)\.htm$ /index.php?cat=$1¦$2¦$3&name=$4 [L]
If you are not committed to using "¦" in your URLs, I would strongly advise you not to. Using this character may cause problems later, since "¦" is a reserved character in URLs and a "command" character in regular expressions and mod_rewrite. A hyhen is actually a better choice.
Jim
i will explain again by following simple example..
my current url is
[mysite.com...]
I want it to be
[mysite.com...]
i did whatever you have mentioned in the first reply but that did not work for me...
it will be graet if you can help me out here :-)
and yes about syntax of Rewriteurl i said NewURL $ OldURL because it worked for me till now..
for example..
my current url was [abc.com...]
so to make it as [abc.com...]
i wrote rule like this:
RewriteRule id(.*)\.htm$ id.php?id=$1
i.e. NewURL$ OldURL
and this worked for me...
anyways..i think i shall not bug you with another doubt now :D
Thank you again for great help.
Regards
Deep
The confusion is apparently due to the context of "old" and "new." You are thinking in terms of the old URL that you used to use versus the new URL that you want to use now. I am thinking in terms of mod_rewrite's function -- the URL being requested (old or input URL) versus the URL needed to locate the requested resource (new or output URL).
The syntax of mod_rewrite in these terms is
RewriteRule <requested or input URL> <actual or output URL>
Jim