Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,148,861 members, 7,802,757 topics. Date: Friday, 19 April 2024 at 08:56 PM

Creating Clean Urls Using Mod Rewrite - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Creating Clean Urls Using Mod Rewrite (1286 Views)

Troubleshooting The Drupal Clean Urls / Troubleshooting The Drupal Clean Urls / How Webmasters Can Make Money By Shortening Urls (2) (3) (4)

(1) (Reply) (Go Down)

Creating Clean Urls Using Mod Rewrite by owambe: 1:22pm On Nov 25, 2013
Hello peeps, i have been trying to get the use of mod re write to create clean urls, basically what i want to achieve is when evera link like this is accessed "index.php?=4" it should be converted to something like this index.php/4/. thanks any post is welcomed,
Re: Creating Clean Urls Using Mod Rewrite by onyengbu: 5:46pm On Nov 26, 2013
owambe: Hello peeps, i have been trying to get the use of mod re write to create clean urls, basically what i want to achieve is when evera link like this is accessed "index.php?=4" it should be converted to something like this index.php/4/. thanks any post is welcomed,

if you know what .htaccess is,

create this lines of code inside it


Options +FollowSymLinks
RewriteEngine On
RewriteRule index.php/(.*)/ index.php?id=$1

HOWEVER if you dont know what .htaccess is,
create a file you will name ".htaccess" put the line above inside it and put in the same directory as your "index.php"

*NB: if you want the url to show as "index/4" rather than "index.php/4", remove the ".php" just before the first "/" in my code.
Ciao
Re: Creating Clean Urls Using Mod Rewrite by owambe: 9:25am On Nov 27, 2013
onye_ngbu*:


if you know what .htaccess is,

create this lines of code inside it

[code]
HOWEVER if you dont know what .htaccess is,
create a file you will name ".htaccess" put the line above inside it and put in the same directory as your "index.php"

*NB: if you want the url to show as "index/4" rather than "index.php/4", remove the ".php" just before the first "/" in my code.
Ciao
it didint work sir pls help

# Enable Rewriting
Options +FollowSymLinks
RewriteEngine on
RewriteRule subscribe.php/(.*)/ subscribe.php?id=$1
Re: Creating Clean Urls Using Mod Rewrite by onyengbu: 9:13am On Nov 28, 2013
owambe:
it didint work sir pls help

# Enable Rewriting
Options +FollowSymLinks
RewriteEngine on
RewriteRule subscribe.php/(.*)/ subscribe.php?id=$1
Tell me exactly ALL you did and let me know what the problem is...
Re: Creating Clean Urls Using Mod Rewrite by owambe: 2:54pm On Nov 28, 2013
i took the snippet u gave me,
created a .htaccess file
inserted the snippet into the .htaccess file
changed the index.php to subscribe.php, because thats the name of my page,
i have tested it locally on xampp and remotely

is there something am doing wrong,
or can u fix a sample for me that i can test and follow.
thanks
Re: Creating Clean Urls Using Mod Rewrite by onyengbu: 7:14am On Nov 29, 2013
owambe: i took the snippet u gave me,
created a .htaccess file
inserted the snippet into the .htaccess file
changed the index.php to subscribe.php, because thats the name of my page,
i have tested it locally on xampp and remotely

is there something am doing wrong,
or can u fix a sample for me that i can test and follow.
thanks
First question is: is .htacces working on your xampp? If it is, hope you werent expecting the code to redirect your original link?

You have to re-structure your link from
<a href="subscribe.php?id=4">Link</a> 
to
<a href="subscribe/4">Link</a> 

Its not that the first link above will no longer work but it wont automatically show up in your address bar as the second one just because of the url. Though that can be achieved but not with this .htaccess code.

Did this answer your question?
Re: Creating Clean Urls Using Mod Rewrite by owambe: 9:56am On Nov 29, 2013
am kinda confused, because if i reconstruct the link to wat u have just said, hw does the content from the database show. cus am displaying the content usin id numbers
Re: Creating Clean Urls Using Mod Rewrite by onyengbu: 10:41am On Nov 29, 2013
owambe: am kinda confused, because if i reconstruct the link to wat u have just said, hw does the content from the database show. cus am displaying the content usin id numbers
Thats the idea bro. The .htaccess code (RewriteRule subscribe/(.*)/ subscribe.php?id=$1) tells Apache server that 'subscribe/4' is a request for 'subscribe.php?id=4' .

Thats the point of the whole thing. You dont need to bother about that. Just find out if the code works. If it works, there will be other new problems that will arise. For example, your css and other linked files might not link corectly and that will affect the page formatting. But that one is no problem at all cos you just need only one line of code to fix that.

Just test first.. I have been through this path before.
Re: Creating Clean Urls Using Mod Rewrite by owambe: 11:17am On Nov 29, 2013
am getting object not found, why, that means the file isnt present

ok on my second attempt, it works, but dosent pass the value to the next page, and also the logo is missing
Re: Creating Clean Urls Using Mod Rewrite by onyengbu: 11:51am On Nov 29, 2013
So it works...

Ok for the missing image:
Put this line in the head section of your page:
<base href="http://yoursite.com"/>


If you are on your local host you can change 'yoursite.com' to somthing like 'localhost/site'.

I dont know your xamp filesystem but yoursite.com should be your server_name.
Re: Creating Clean Urls Using Mod Rewrite by owambe: 12:10pm On Nov 29, 2013
WHAT ABOUT THE DETAILS THAT ARE NOT PASSED TO THE OTHER PAGE, FROM MY DATABASE, BECAUSE THATS IS THE ESSENCE OF MY URL
Re: Creating Clean Urls Using Mod Rewrite by onyengbu: 7:12pm On Nov 29, 2013
owambe: WHAT ABOUT THE DETAILS THAT ARE NOT PASSED TO THE OTHER PAGE, FROM MY DATABASE, BECAUSE THATS IS THE ESSENCE OF MY URL
i dont get you. Are you saying that database row with id of 4 is not returned from db? I really dont get your question.
Did the image and css work with the fix i gave you above?
Re: Creating Clean Urls Using Mod Rewrite by olyivy(f): 10:37pm On Nov 30, 2013
where is owambe naa?

Oh! Ok, its owambe time already! where is owambe naa?

Oh! Ok, its owambe time already! grin
Re: Creating Clean Urls Using Mod Rewrite by owambe: 9:38am On Dec 02, 2013
onye_ngbu*:
i dont get you. Are you saying that database row with id of 4 is not returned from db? I really dont get your question.
Did the image and css work with the fix i gave you above?
yes it didnt work, the data from row 4 didnt work. the images part worked.
Re: Creating Clean Urls Using Mod Rewrite by onyengbu: 12:34pm On Dec 02, 2013
owambe: yes it didnt work, the data from row 4 didnt work. the images part worked.
Now tell me, how did you link your connection script to susbcribe.php
Let's start from there?
Re: Creating Clean Urls Using Mod Rewrite by owambe: 2:05pm On Dec 02, 2013
onye_ngbu*:

Now tell me, how did you link your connection script to susbcribe.php
Let's start from there?
using the include('"wink;, method, and its been working until i tried working with the clean urls
Re: Creating Clean Urls Using Mod Rewrite by onyengbu: 3:05am On Dec 03, 2013
owambe: using the include('"wink;, method, and its been working until i tried working with the clean urls
i thought as much. Now can u tell me:
1. your directory structure relative to subscribe.php and the included file? Are they in the same directory? Or not?

2. Are there other included files in subscribe.php and if yes, at which point in your page was the db connection file included?

The reason why i am asking all these questions is that i experienced it first hand i solved it on my own, needless to say it gave me tough time but at the end it all made me sort of a voice on that issue.
These problem occur because, with the new way you display your url, its become a bit hard for files on a page whose normal filename has been rewritten to link all the files that run that page.

Your externally linked css, js files a bound to suffer challenges unless you linked them like say:
<link href='http://yourdomain.com/css/style.css' type='css' />
rather than
<link href='css/style.css' type='css' />


the includes are not supposed to be affected by the linking issue but i suspect something else is amiss.
If it were me, there are many ways i'll troubleshoot this. For e.g, i will put the connection code directly on susbscribe.php and make sure i include die(mysql_error()) in my query just to root out that side of the problem.

(1) (Reply)

Need Help On HTML Code / High PR Dofollow Social Bookmarking Site List 2015 / Webmasters How Do I Increase The Size Of The Text In My signature?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 36
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.