Currently i have a site structure like http://www.example.com/news.php?cat=1&ID=53
Now i want it to look like
http://www.example.com/news/1/53 or similar
I have heard that this can be performed incase of Apache using modrewrite
My problem is that i have already mentioned http://www.example.com/news.php?cat=1&ID=53 in many scripts and cannot change it... or i don't want to. just want that when user goes to http://www.example.com/news.php?cat=1&ID=53 the url he views on browser be http://www.example.com/news/1/53
And if i want to make my own extension such as .kkonline then that to is possible without changing the links that already exist?
Is that possible? How? give me some tips on modrewrite too if any. Or where can i get easy touse tutorial for modrewrite (.htaccess file i guess has to be changed. Correct?)
Mod Rewrite
Moderator: General Moderators
You can use both http://www.example.com/news.php?cat=1&ID=53 and http://www.example.com/news/1/53
But if you have a lot of links with ?cat=1....etc...etc ad you do not want to change them what is the benefit of mod rewrite then?
But if you have a lot of links with ?cat=1....etc...etc ad you do not want to change them what is the benefit of mod rewrite then?
- iknownothing
- Forum Contributor
- Posts: 337
- Joined: Sun Dec 17, 2006 11:53 pm
- Location: Sunshine Coast, Australia
This may be of interest.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Re: Mod Rewrite
Mod rewrite can use a form of regular expression to move things around. Unfortunately I don't have a link to any useful tutorials easily at hand.
. Unfortunately this is not always a sensible decision. Surely it is often easier to correct something earlier than continue replicating things which may need changing at a later date or even worse building dependancies on other things to fudge over problems. The only real exception is when a site is running, you need a quick fix now and implement it but then you should still go back and solve the problem properly (with the approriate testing).
You could for instance set up a variable/constant for common links...
If you need to change the link for any reason you only have one place (the definition file) to change it. Of course this may be overkill in your scenario but is just one of a number of possibilities to make your life easier once an initial change is done.
I would guess that this is more a case of don't want tokkonline wrote:cannot change it... or i don't want to.
You could for instance set up a variable/constant for common links...
Code: Select all
// this is included into every php file where links are needed or defined as a constant
$news_page_link="http://www.example.com/news.php?cat=%d&ID=%d";
...
...
// When you need to output (could be in multiple locations/files)
printf($news_page_link,$catid,$id);