UrlRewrite htaccess confusion
UrlRewrite htaccess confusion
am 28.10.2009 22:00:09 von Rob Gould
I feel like I'm really close to a solution for the clean-url method in
htaccess. I've successfully got it now so that:
http://benchwarmersports.com/packages/basketball/2010/nba-al l-star-game
maps to:
http://benchwarmersports.com/packages.php?category=basketbal l&year=2010&title=nba-all-star-game
However, I'm finding that when I click on subsequent links from:
http://benchwarmersports.com/packages/basketball/2010/nba-al l-star-game
that I land in a strange url-structure where it replicates the
packages part of the url.
Can someone tell me what I might need to change about my rewrite logic
to fix this issue? I'm getting lost in the world of base urls and
recursive rewrites...
Present htaccess code:
Options +FollowSymlinks
RewriteEngine On
RewriteOptions MaxRedirects=10
RewriteBase /
RewriteRule ^packages/([^/]+)/([^/]+)/([^/]+)$ /packages.php?category=
$1&year=$2&title=$3 [NC]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: UrlRewrite htaccess confusion
am 29.10.2009 15:52:34 von Shawn McKenzie
Rob Gould wrote:
> I feel like I'm really close to a solution for the clean-url method in
> htaccess. I've successfully got it now so that:
>
> http://benchwarmersports.com/packages/basketball/2010/nba-al l-star-game
>
> maps to:
>
> http://benchwarmersports.com/packages.php?category=basketbal l&year=2010&title=nba-all-star-game
>
>
> However, I'm finding that when I click on subsequent links from:
>
> http://benchwarmersports.com/packages/basketball/2010/nba-al l-star-game
>
> that I land in a strange url-structure where it replicates the packages
> part of the url.
>
> Can someone tell me what I might need to change about my rewrite logic
> to fix this issue? I'm getting lost in the world of base urls and
> recursive rewrites...
>
It's hard to tell without seeing the link and/or what code you use to
generate it, but off the top of my head I would say that it's not a
rewrite issue. It seems to be an issue with using relative URLs in your
links. If you are on this page (this is in your browser address bar):
http://benchwarmersports.com/packages.php?category=basketbal l&year=2010&title=nba-all-star-game
The browser will interpret all relative links like 'somefile.php' as:
http://benchwarmersports.com/somefile.php
But if you use your rewritten URL, then the browser will see relative
links as one of the following (not sure which without testing):
http://benchwarmersports.com/packages/basketball/2010/nba-al l-star-game/somefile.php
--or--
http://benchwarmersports.com/packages/basketball/2010/somefi le.php
This is because it is interpreting the slashes as path separators. You
probably need to generate absolute URLs in your links.
--
Thanks!
-Shawn
http://www.spidean.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: UrlRewrite htaccess confusion
am 29.10.2009 16:26:04 von Rob Gould
You are indeed correct! Absolute URLs for everything, images, css,
javascript, and links fixed the issue. Took me forever to change
every link in the whole site, but it's happy now. Seems like there
ought to be an easier way.
On Oct 29, 2009, at 10:52 AM, Shawn McKenzie wrote:
> Rob Gould wrote:
>> I feel like I'm really close to a solution for the clean-url method
>> in
>> htaccess. I've successfully got it now so that:
>>
>> http://benchwarmersports.com/packages/basketball/2010/nba-al l-star-game
>>
>> maps to:
>>
>> http://benchwarmersports.com/packages.php?category=basketbal l&year=2010&title=nba-all-star-game
>>
>>
>> However, I'm finding that when I click on subsequent links from:
>>
>> http://benchwarmersports.com/packages/basketball/2010/nba-al l-star-game
>>
>> that I land in a strange url-structure where it replicates the
>> packages
>> part of the url.
>>
>> Can someone tell me what I might need to change about my rewrite
>> logic
>> to fix this issue? I'm getting lost in the world of base urls and
>> recursive rewrites...
>>
>
> It's hard to tell without seeing the link and/or what code you use to
> generate it, but off the top of my head I would say that it's not a
> rewrite issue. It seems to be an issue with using relative URLs in
> your
> links. If you are on this page (this is in your browser address bar):
> http://benchwarmersports.com/packages.php?category=basketbal l&year=2010&title=nba-all-star-game
>
> The browser will interpret all relative links like 'somefile.php' as:
> http://benchwarmersports.com/somefile.php
>
> But if you use your rewritten URL, then the browser will see relative
> links as one of the following (not sure which without testing):
>
> http://benchwarmersports.com/packages/basketball/2010/nba-al l-star-game/somefile.php
>
> --or--
>
> http://benchwarmersports.com/packages/basketball/2010/somefi le.php
>
> This is because it is interpreting the slashes as path separators.
> You
> probably need to generate absolute URLs in your links.
>
> --
> Thanks!
> -Shawn
> http://www.spidean.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: UrlRewrite htaccess confusion
am 29.10.2009 16:31:27 von Ashley Sheridan
--=-q6yCsVgLFIR8pm47ZxzT
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
On Thu, 2009-10-29 at 11:26 -0400, Rob Gould wrote:
> You are indeed correct! Absolute URLs for everything, images, css,
> javascript, and links fixed the issue. Took me forever to change
> every link in the whole site, but it's happy now. Seems like there
> ought to be an easier way.
>
>
> On Oct 29, 2009, at 10:52 AM, Shawn McKenzie wrote:
>
> > Rob Gould wrote:
> >> I feel like I'm really close to a solution for the clean-url method
> >> in
> >> htaccess. I've successfully got it now so that:
> >>
> >> http://benchwarmersports.com/packages/basketball/2010/nba-al l-star-game
> >>
> >> maps to:
> >>
> >> http://benchwarmersports.com/packages.php?category=basketbal l&year=2010&title=nba-all-star-game
> >>
> >>
> >> However, I'm finding that when I click on subsequent links from:
> >>
> >> http://benchwarmersports.com/packages/basketball/2010/nba-al l-star-game
> >>
> >> that I land in a strange url-structure where it replicates the
> >> packages
> >> part of the url.
> >>
> >> Can someone tell me what I might need to change about my rewrite
> >> logic
> >> to fix this issue? I'm getting lost in the world of base urls and
> >> recursive rewrites...
> >>
> >
> > It's hard to tell without seeing the link and/or what code you use to
> > generate it, but off the top of my head I would say that it's not a
> > rewrite issue. It seems to be an issue with using relative URLs in
> > your
> > links. If you are on this page (this is in your browser address bar):
> > http://benchwarmersports.com/packages.php?category=basketbal l&year=2010&title=nba-all-star-game
> >
> > The browser will interpret all relative links like 'somefile.php' as:
> > http://benchwarmersports.com/somefile.php
> >
> > But if you use your rewritten URL, then the browser will see relative
> > links as one of the following (not sure which without testing):
> >
> > http://benchwarmersports.com/packages/basketball/2010/nba-al l-star-game/somefile.php
> >
> > --or--
> >
> > http://benchwarmersports.com/packages/basketball/2010/somefi le.php
> >
> > This is because it is interpreting the slashes as path separators.
> > You
> > probably need to generate absolute URLs in your links.
> >
> > --
> > Thanks!
> > -Shawn
> > http://www.spidean.com
>
>
There is, use the tag in your HTML. Don't forget that while
you're rewriting the URLs, all the work is being done server-side. The
browser thinks that the location of the document it is being served is
in the path that the user typed into the location bar, so all relative
links are relative to that.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--=-q6yCsVgLFIR8pm47ZxzT--
Re: UrlRewrite htaccess confusion
am 29.10.2009 18:26:10 von Shawn McKenzie
Rob Gould wrote:
> You are indeed correct! Absolute URLs for everything, images, css,
> javascript, and links fixed the issue. Took me forever to change every
> link in the whole site, but it's happy now. Seems like there ought to
> be an easier way.
>
There is an easier way. The logic depends upon your app, but create a
function that builds and optionally echos URLs for you. It can work out
the base url or you can do that when you initialize your app and define
it as a constant. It can be as simple or as complex as you need.
-- or --
echo '';
--
Thanks!
-Shawn
http://www.spidean.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: UrlRewrite htaccess confusion
am 29.10.2009 18:31:58 von Shawn McKenzie
Shawn McKenzie wrote:
> Rob Gould wrote:
>> You are indeed correct! Absolute URLs for everything, images, css,
>> javascript, and links fixed the issue. Took me forever to change every
>> link in the whole site, but it's happy now. Seems like there ought to
>> be an easier way.
>>
>
> There is an easier way. The logic depends upon your app, but create a
> function that builds and optionally echos URLs for you. It can work out
> the base url or you can do that when you initialize your app and define
> it as a constant. It can be as simple or as complex as you need.
>
>
>
> -- or --
>
> echo '';
>
Or the simplist approach is to define at constant at app initialization
and use it:
echo 'Something';
--
Thanks!
-Shawn
http://www.spidean.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: UrlRewrite htaccess confusion
am 29.10.2009 18:40:20 von Martin Scotta
--000325554266bef0aa047716674f
Content-Type: text/plain; charset=ISO-8859-1
You can use a regexp for search and replace in your files.
packages.php?category=([^&]+)&year=([^&]+)&title=([^&]+)
The problem is those values are variables on the code.
As Shawn said, it is easier to provide some function to create links.If you
need to change all links you only change the function and the work is done.
cheers,
On Thu, Oct 29, 2009 at 2:31 PM, Shawn McKenzie wrote:
> Shawn McKenzie wrote:
> > Rob Gould wrote:
> >> You are indeed correct! Absolute URLs for everything, images, css,
> >> javascript, and links fixed the issue. Took me forever to change every
> >> link in the whole site, but it's happy now. Seems like there ought to
> >> be an easier way.
> >>
> >
> > There is an easier way. The logic depends upon your app, but create a
> > function that builds and optionally echos URLs for you. It can work out
> > the base url or you can do that when you initialize your app and define
> > it as a constant. It can be as simple or as complex as you need.
> >
> >
> >
> > -- or --
> >
> > echo '';
> >
>
> Or the simplist approach is to define at constant at app initialization
> and use it:
>
> echo 'Something';
>
> --
> Thanks!
> -Shawn
> http://www.spidean.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Martin Scotta
--000325554266bef0aa047716674f--
Re: Re: UrlRewrite htaccess confusion
am 29.10.2009 20:44:06 von Paul M Foster
On Thu, Oct 29, 2009 at 12:26:10PM -0500, Shawn McKenzie wrote:
> Rob Gould wrote:
> > You are indeed correct! Absolute URLs for everything, images, css,
> > javascript, and links fixed the issue. Took me forever to change every
> > link in the whole site, but it's happy now. Seems like there ought to
> > be an easier way.
> >
>
> There is an easier way. The logic depends upon your app, but create a
> function that builds and optionally echos URLs for you. It can work out
> the base url or you can do that when you initialize your app and define
> it as a constant. It can be as simple or as complex as you need.
>
>
>
> -- or --
>
> echo '';
+1
I initialize a "links" class from the config, and then use it to serve
up link text and URLs depending on the parameters I give it.
Paul
--
Paul M. Foster
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php