Forum Moderators: phranque

Message Too Old, No Replies

Basic help with Apache .htaccess

         

impact

11:53 am on Sep 4, 2010 (gmt 0)

10+ Year Member



Hello

I need help on this, I am trying to redirect

event.domain.com/<username>/<event>

to

domain.com?event?username=<username>&id=<event>

Any help will be appreciated.

Thank you,

g1smd

12:44 pm on Sep 4, 2010 (gmt 0)

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



Are you sure you need a redirect to a new URL which will be exposed to users, or are you looking for a rewrite to serve content from a script but using a "friendly" URL to access it?

There's more than ten thousand prior examples of such code in this forum. Please post your best effort code for discussion.

jdMorgan

2:51 pm on Sep 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And a full tutorial: Changing Dynamic URLs to Static URLs [webmasterworld.com]

Jim

impact

3:04 pm on Sep 4, 2010 (gmt 0)

10+ Year Member



Thank you all for replying.

I am new to this, so I actually not sure what I want. All I want is, when the user enter

domain.com/<username>/<event>

I should be able to get the URL value using a PHP script page here

domain.com/show?username=<username>&id=<event>

Now whether this should be URL redirect or internal server interpretation, I am confused on this. You tell me what would be best for me?

All I can this is not about SEO. For me this is all about running the PHP script.

Thank you,

g1smd

4:43 pm on Sep 4, 2010 (gmt 0)

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



The linked tutorial explains it all. A redirect makes the user agent (that's your browser) ask for a NEW URL. A rewrite gets content from a non-default location inside the server and delivers it for the originally requested URL.

impact

1:20 am on Sep 5, 2010 (gmt 0)

10+ Year Member



Please correct me if I am wrong

event.example.com/<username>/<event>
TO
event.example.com/show?username=<username>&id=<event>



Options +FollowSymLinks
RewriteEngine on

RewriteCond %{THE_REQUEST}http://example.com/%1/%2? [R=301,L]
RewriteRule ^event.example.com\ /show\.php\username=([^&]+)&id=([^&]+)\ HTTP/


Any help will be appreciated. Thank you.

impact

1:24 am on Sep 5, 2010 (gmt 0)

10+ Year Member



In addition to this, please some one tell me how do I add exception. For example. Directory such as "account" and "help" should not be redirected but any thing other that, should always be redirected.

Exceptions:
event.example.com/account/login
event.example.com/help/files

Thank you,

jdMorgan

8:10 pm on Sep 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It looks like you are copying, pasting, and guessing.... A method that is almost certainly doomed to failure. Please make note of the thread I cited above, and take advantage of the resources available in our Apache Forum Charter and Apache Forum Library (see links above on this page).

Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^event\.example\.com
RewriteCond $1 !^(account|help)$
RewriteRule ^([a-z0-9\-]+)/([^/.]+)$ /show.php?username=$1&id=$2 [NC,L]

The first rewritecond is only needed if this .htaccess file executes when more than one hostname is requested -- that is, it's only needed if several domains and/or subdomains 'share' the filespace in which this code is located.

Jim

impact

1:48 am on Sep 9, 2010 (gmt 0)

10+ Year Member



Thank you,