Forum Moderators: phranque

Message Too Old, No Replies

htaccess rewrite problem

htaccess rewrite problem

         

furboy10

12:51 pm on Jul 2, 2011 (gmt 0)

10+ Year Member



Hello,

I want to rewrite like below

from [xyz.com...]
to [xyz.com...]

Please advise the code if htaccess file is in the images folder.

wilderness

1:04 pm on Jul 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Forum Charer [webmasterworld.com]

Forum Etiquette:

Please do not post specific details such as domain names, full IP addresses, or personally-identifiable information such as name, e-mail address, IM screen name, etc. Such specifics will be edited or removed in accordance with our Terms of Service [webmasterworld.com], which may render your post meaningless. Please replace all instances of your domain name with "example.com" before posting.

furboy10

1:17 pm on Jul 2, 2011 (gmt 0)

10+ Year Member



Hello,

I want to rewrite like below

from example.com/images/1.htm to example.com/images/index.htm?imageid=1

Please advise the code if htaccess file is in the images folder.

g1smd

1:33 pm on Jul 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



When the RewriteRule target is a URL (as in your example) this would be an example of an external redirect.

When you need an internal rewrite (which is what you asked for), the RewriteRule target will be an internal folder path and filename without domain name specified.

Your question includes a mixture of both of these concepts, so please clarify whether you want an "external redirect to a new URL" or an "internal rewrite to a non-default server filepath and file".

wilderness

1:36 pm on Jul 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Please advise the code


Forum Charer [webmasterworld.com]

Forum Etiquette:

It is not appropriate to expect other members to write your code for you or to debug your entire project; Please don't expect other members to solve a problem you don't want to begin solving yourself.

Before posting a new thread, please try looking through the older posts in the forum index. Someone may have recently asked the same question, and you may benefit from the posted answers. Using the WebmasterWorld search function or the site-specific search feature of major search engines may help you find exactly what you are looking for on WebmasterWorld.

"Fix my code" and "Do my homework for me" threads:

This is a discussion forum, not a help desk or a free code-writing service; If you have a problem, please try to research it and then phrase your post in a manner conducive to general discussion of the issue. Rather than providing one-off solutions, we prefer to help people find resources to help themselves.

A general guideline for code-related problems is: Post your own code and describe what you hoped it would accomplish. Then describe how it fails and include all relevant information from your server error logs. Too-general posts in the form of "What code do I use to do this?" often go unanswered for a long time.

The following resources are often referenced in our Apache forum, and may help to answer or focus your questions.

end of quote

Your request is the most common in this forum. 3-4 times weekly. There are literally thousands of examples in the archives.

Please read both the Forum Charter and the Forum Library in their entirety.
There are examples (with links) that provide information.

furboy10

1:39 pm on Jul 2, 2011 (gmt 0)

10+ Year Member



it is an internal redirect within the folder

wilderness

1:48 pm on Jul 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



string+2011 [google.com]

g1smd

2:09 pm on Jul 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I asked you to clarify whether you wanted "external redirect" or "internal rewrite" and you have responded with "internal redirect", the same issue as in your original post.

lucy24

3:54 pm on Jul 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



it is an internal redirect within the folder

You may be getting confused by the words "internal" and "external". Calling something "external" doesn't necessarily mean that you're going somewhere else. If it's easier, think of them as "invisible" and "visible". In a rewrite, the user's address bar shows whatever they originally asked for, even though you've physically sent them to a different place. In a redirect, the address bar shows the new address.

In the case of image files, it should make no difference, because humans don't see the address anyway, and images don't link to anything further such as style sheets. But if you have really relocated files, you need to redirect so search engines will look in the right place. (Sure, you can rewrite, but then the rule will be cluttering up your htaccess forever. Redirects can be thrown away after a year or so.)

furboy10

4:27 pm on Jul 2, 2011 (gmt 0)

10+ Year Member



Sir, to make it simpler when the user enters example.com\images\1.htm i want to get the imageid in this case 1 into a php file named image.php. so the user bar would show the same thing.

furboy10

4:42 pm on Jul 2, 2011 (gmt 0)

10+ Year Member



got the solution "RewriteRule ^([0-9]+)\.htm$ index.htm?imageid=$1"