Jump to content

Recommended Posts

Hi am trying to make my urls like this with username instead of id numbers.

 

http://www.mysite.com/index.php?act=showmember=davie33

 

And like this.

http://www.mysite.com/showmember/davie33.html

 

This is my code for seo yes and no.How do i redo this ?.

 

if ( $seo=='yes') {
$memberlink = $siteurl.'showmember/'.$id.'.html';
} else {
$memberlink = $siteurl . 'index.php?act=showmember&id='.$id;
}

 

And how would i do this for htaccess file ?.

Link to comment
https://forums.phpfreaks.com/topic/256268-url-help-please/
Share on other sites

try this

RewriteEngine on
RewriteRule ([^/]+)/([^/]+)\.html$ /act=$1=$2 [L] 

 

and this

http://www.mysite.com/ABC/davie33.html

should become

http://www.mysite.com/act=ABC=davie33

 

 

OR

 

RewriteEngine on
RewriteRule showmember/([^/]+)\.html$ /act=showmember=$1 [L] 

 

for sticky showmember

 

Link to comment
https://forums.phpfreaks.com/topic/256268-url-help-please/#findComment-1313760
Share on other sites

try this

RewriteEngine on
RewriteRule ([^/]+)/([^/]+)\.html$ /act=$1=$2 [L] 

 

and this

http://www.mysite.com/ABC/davie33.html

should become

http://www.mysite.com/act=ABC=davie33

 

 

OR

 

RewriteEngine on
RewriteRule showmember/([^/]+)\.html$ /act=showmember=$1 [L] 

 

for sticky showmember

 

so for the php code part of it would i fix that if i use option one ?.

 

if ( $seo=='yes') {
$memberlink = $siteurl.'showmember/'.$id.'.html';
} else {
$memberlink = $siteurl . 'index.php?act=showmember&id='.$id;
}

Link to comment
https://forums.phpfreaks.com/topic/256268-url-help-please/#findComment-1313764
Share on other sites

If that .htaccess file exists and apache mod_rewrite is on, then

 

both links

1. http://www.mysite.com/showmember/davie33.html

2. http://www.mysite.com/showmember=ABC=davie33

will go to index.php

 

Where as without the .htaccess file only link 2 would work

the PHP would just need to use $_GET['showmember'] to get davie33

 

**Correction!**

showmember=ABC=davie33  ???

this that right ?

 

I assume you mean

?act=ABC&id=davie33

 

Update .htaccess to

RewriteRule ([^/]+)/([^/]+)\.html$ /?act=$1&id=$2 [L] 

thus $_GET['id'] would be davie33

and $_GET['act'] would be showmember

Link to comment
https://forums.phpfreaks.com/topic/256268-url-help-please/#findComment-1313766
Share on other sites

Its bad for SEO, BUT required for code ;)

 

But as your going to be using pretty URL's that are good for SEO, so it will cancel out the bad  :P

 

So here is the logic

 

<?php
echo "Action ".$_GET['act'];
echo "\n<br />"; 
echo "I am Member ".$_GET['id'];
?>

 

Add .htaccess

RewriteEngine on
RewriteRule ([^/]+)/([^/]+)\.html$ /?act=$1&id=$2 [L] 

 

Now test

 

test links (OLD style) with 2 gets

http://www.mysite.com/?act=showmember=&id=davie33

http://www.mysite.com/?act=killuser=&id=davie33

 

test links (NEW style) with well none!

http://www.mysite.com/showmember/davie33.html

http://www.mysite.com/killuser/davie33.html

 

Link to comment
https://forums.phpfreaks.com/topic/256268-url-help-please/#findComment-1313774
Share on other sites

This is my act from my index.php

switch($_GET['act']){
case 'showmember':
include ("templates/".$theme."/showmember.php");
break;
}

 

this is my R/rule

 

RewriteRule showmember/(.*)\.html$ index.php?act=showmember&id=$1

 

I want to keep it in same format but without the id number showing.

 

This is my php code link that will show my members.

 

<a href="<?php echo $memberlink;?>"><?php echo $username;?></a>

 

Which takes me to

http://www.mysite.com/index.php?act=showmember&id=2

http://www.mysite.com/showmember/2.html

 

How do i do it like you said but keeping it in same format with showmember in link

like this

http://www.mysite.com/index.php?act=showmember$id=davie33 <<<<< as username

http://www.mysite.com/showmember/davie33.html

 

I know it works like this.

if ( $seo=='yes') {
$memberlink = $siteurl.'showmember/'.$id.'/'.$username.'.html';
} else {
$memberlink = $siteurl . 'index.php?act=showmember&id='.$id.'='.$username;
}

 

Which gives u link like this.

http://www.mysite.com/showmember/1/davie33.html

http://www.mysite.com/index.php?act=showmember$id=1=davie33

Which is bad for the 2nd link.

 

Am just trying to break it down abit for you from my code and i am trying to understand what your saying.

Link to comment
https://forums.phpfreaks.com/topic/256268-url-help-please/#findComment-1313787
Share on other sites

what your need to do is add a routine to allow lookups by UserName,

 

for example

I assume it currently has a SQL statement like this

SELECT * FROM Users WHERE userID= $_GET['id']

 

your need to update it

to something like this

SELECT * FROM Users WHERE username= $_GET['username']

 

then add the htaccess

RewriteEngine on
RewriteRule showmember/([^/]+)\.html$ /?act=$1&username=$2 [L] 

 

Now in the showmember.php file, i assume you have

if(isset($_GET['id'])){
     $query = mysql_query("SELECT * FROM Users WHERE userID=%d",$_GET['id']);
}

you could update that so it handles both ie

if(isset($_GET['id'])){
     $query = mysql_query("SELECT * FROM Users WHERE userID=%d",$_GET['id']);
}elseif(isset($_GET['username'])){
     $query = mysql_query("SELECT * FROM Users WHERE userID=%d",$_GET['id']);
}

Link to comment
https://forums.phpfreaks.com/topic/256268-url-help-please/#findComment-1313854
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.