Forum Moderators: phranque

Message Too Old, No Replies

.htaccess rewrite questions - how to change page and keep rest of URL

         

smadadi

3:44 pm on Nov 6, 2011 (gmt 0)

10+ Year Member



Hello,

I am having a problem with my site - I need to change a single part of my page URL - see below:

/dyncat/index.php/catalog2/show_catalog/CALDWELL/11

needs to be changed so that index.php is changed to index.php? with the rest of the string following being kept regardless of it's contents - so it would change to:

/dyncat/index.php?/catalog2/show_catalog/CALDWELL/11

I've been looking at .htaccess redirecting but can't wrap my head around how to get this working - any ideas?

lucy24

9:29 pm on Nov 6, 2011 (gmt 0)

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



Before you can wrap your head around the mechanics you have to wrap your head around the concept. Apache is not a cut-and-paste language; you can seriously hurt yourself that way.

I think possibly what you mean is:

You want the user to see an URL in the first form (the one without a query string) but you want to serve content from the second location (the one with a query string).

Either way, the extension-plus-slash sequence (.php/) is not going to work.

For starters, you need to know two things: what is the current form of the link your users are following, and where does the material really live? That's assuming your site already exists. If you are making a new site, get it exactly right so you don't have to change things later. If you are changing an existing site, find a layout that will be good in the long term and that will work smoothly with any old-format links that are still floating around.

:: wondering if it would do any good to write up some boilerplate on the redirect-to-rewrite two-step ::

g1smd

9:34 pm on Nov 6, 2011 (gmt 0)

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



Unescaped slashes are not a valid character in a query string.

Why do you want to change from using friendly URLs to those with paramters?

smadadi

10:32 pm on Nov 6, 2011 (gmt 0)

10+ Year Member



The site already exists and the URL change I need is exactly as I specified - with the only difference being the change from index.php to index.php? in the string.

It is using CodeIgniter and was working fine until my host switched to PHP5 - now the only way I can find that I can get it working is to change index.php to index.php? - I've tried numerous other suggestions.

g1smd

11:10 pm on Nov 6, 2011 (gmt 0)

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



Sounds like applying a band-aid on a broken leg.

Using an internal rewrite, you could keep the URLs the same. That would at least see no external change for the URL structure.

smadadi

11:51 pm on Nov 6, 2011 (gmt 0)

10+ Year Member



I agree - I am looking for a short-term fix to get the site working as soon as possible as it is currently broken - then I can do a proper restructure.

Could you help me with the internal rewrite rule please? I have very little knowledge of this system

g1smd

11:57 pm on Nov 6, 2011 (gmt 0)

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



RewriteRule ^dyncat/index.php/catalog2/show_catalog/CALDWELL/11$ /dyncat/index.php?/catalog2/show_catalog/CALDWELL/11 [L]

smadadi

12:08 am on Nov 7, 2011 (gmt 0)

10+ Year Member



How would I do it so that it keeps the string after index.php/ regardless of what it is? i.e. it could be:

dyncat/index.php/catalog2/etc./etc.
dyncat/index.php/admin/etc./etc.
dyncat/index.php/test/etc.

g1smd

12:18 am on Nov 7, 2011 (gmt 0)

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



You'll need a Regular Expression to match.

At this point, you'll need to careflly read a few tutorials on those.