Jump to content

Recommended Posts

I have changed the htaccess file so this;


website.com/whatson.php?event_id=1&cat_name=comedy&event_name=some ones name

 

changes to this;

 

website.com/whatson/1-some ones name.html

 

using:


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
rewriterule ^whatson/([^-]+)-([^&]+)\.html$ /whatson.php?event_id=$1&cat_name=$2&event_name=$3 [L]
</IfModule>

 

So, if i add the link to the browser it works fine. One thing that i cant get my head around (and yes, ive been searching around for the last few days!)....what php code do i need to have to change the actual links in my webpage (below) to a seo friendly link?

 


<a href="whatson.php<?php echo $row_main['event_id']; ?>&cat_name=<?php echo $row_main['cat']; ?> &event_name=<?php echo $row_main['eventname']; ?>"

 

 

...i hope someone could literally spell it out for me...thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/167394-seo-friendly-link/
Share on other sites

You change the link to your new SEO friendly url.

 

So it'll be

<a href="whatson/<?php echo $row_main['event_id']; ?>-<?php echo $row_main['cat']; ?>-<?php echo $row_main['eventname']; ?>"

 

Thanks for your quick reply...so now to part 2!

 

How do i redefine the sent values (id's etc) in the next page for a mysql query...

Link to comment
https://forums.phpfreaks.com/topic/167394-seo-friendly-link/#findComment-882656
Share on other sites

Okay so the short answer is you can't. Not without passing them in the url as before.  You can make the buttons into form submit buttons, with hidden fields passing, but that no longer really makes them links.  Alternatively you could parse the new url for the info, since the new link is unique and contains the id, name, etc.. right?

Link to comment
https://forums.phpfreaks.com/topic/167394-seo-friendly-link/#findComment-882659
Share on other sites

Okay so the short answer is you can't. Not without passing them in the url as before.  You can make the buttons into form submit buttons, with hidden fields passing, but that no longer really makes them links.  Alternatively you could parse the new url for the info, since the new link is unique and contains the id, name, etc.. right?

barney0o0 is using mod_rewrite. So not sure what you're suggesting

Link to comment
https://forums.phpfreaks.com/topic/167394-seo-friendly-link/#findComment-882661
Share on other sites

Okay so the short answer is you can't. Not without passing them in the url as before.  You can make the buttons into form submit buttons, with hidden fields passing, but that no longer really makes them links.  Al

ternatively you could parse the new url for the info, since the new link is unique and contains the id, name, etc.. right?

barney0o0 is using mod_rewrite. So not sure what you're suggesting

 

Right.  He is using mod_rewrite, so that if a user were to go to www.somepage.com/somepage.php?id=1&name=Joe it would be rewritten to www.somepage.com/1-Joe/  well the problem is that now on his pages he wants to make his links be www.somepage.com/1-Joe/  so he's not actually passing params in the url anymore.

Link to comment
https://forums.phpfreaks.com/topic/167394-seo-friendly-link/#findComment-882670
Share on other sites

That is down to your rewrite rule. Which is

rewriterule ^whatson/([^-]+)-([^&]+)\.html$ /whatson.php?event_id=$1&cat_name=$2&event_name=$3 [L]

The url to the right (highlighted) is what your PHP script see's. The parts in red will be your $_GET vars. As I mention earlier

 

As you would normally would using the $_GET superglobal. The variables you'll need are $_GET['event_id'] $_GET['cat_name'] $_GET['event_name']

Link to comment
https://forums.phpfreaks.com/topic/167394-seo-friendly-link/#findComment-882672
Share on other sites

Okay so maybe I'm being a nub here (haven't really used modrewrite all that much). So you are saying that when you have that rule in .htaccess, on an actual page you can do

 

<a href='somepage.php/1-blah/'>go to blah page!</a>

 

and because of the rewrite rule, I can use $_GET['event_id'], $_GET['event_name'], etc..?

Link to comment
https://forums.phpfreaks.com/topic/167394-seo-friendly-link/#findComment-882676
Share on other sites

Okay so maybe I'm being a nub here (haven't really used modrewrite all that much). So you are saying that when you have that rule in .htaccess, on an actual page you can do

 

<a href='somepage.php/1-blah/'>go to blah page!</a>

 

and because of the rewrite rule, I can use $_GET['event_id'], $_GET['event_name'], etc..?

Basically yes.

Link to comment
https://forums.phpfreaks.com/topic/167394-seo-friendly-link/#findComment-882680
Share on other sites

sooooooooooo, hopefully this will be last bit. for the query, would i use something like

 

$passedid = $_GET['event_id'];

 

or do i need to refer the rewrite ($1) value?

 

oh, and thanks very much for your help with this

 

 

 

That is down to your rewrite rule. Which is

rewriterule ^whatson/([^-]+)-([^&]+)\.html$ /whatson.php?event_id=$1&cat_name=$2&event_name=$3 [L]

The url to the right (highlighted) is what your PHP script see's. The parts in red will be your $_GET vars. As I mention earlier

 

As you would normally would using the $_GET superglobal. The variables you'll need are $_GET['event_id'] $_GET['cat_name'] $_GET['event_name']

Link to comment
https://forums.phpfreaks.com/topic/167394-seo-friendly-link/#findComment-882682
Share on other sites

@barney0o0 Just to let you know your current rewriteRule will not work as you'd expect. it will only pass over the event id and category. You should this as the rewrite rule instead:

rewriteRule ^whatson/([0-9+])-([A-Z0-9_]+)-([A-Z0-9_]+).html$ /whatson.php?event_id=$1&cat_name=$2&event_name=$3 [NC,L]

Link to comment
https://forums.phpfreaks.com/topic/167394-seo-friendly-link/#findComment-882687
Share on other sites

ok, i had a 'play' yesterday....without any problems, but a couple of questions.

 

as a update, links are as;

 

<a href="whatson_detail/<?php echo $row_Recordset1['event_id']; ?>/<?php echo $row_Recordset1['cat_name']; ?>/<?php echo $row_Recordset1['event_name']; ?>.html"

 

andf the htacces file is;

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
rewriterule ^whatson_detail/([^-]+)/([^&]+)\.html$ /whatson.php?event_id=$1&cat_name=$2&event_name=$3 [L]
</IfModule>

(the event name $3 isnt important as passed variable, so i left it out)

 

so, questions, questions..

 

If i want to add 2 more links (one to whatson.php and another to whatson.php?<?php echo $row_Recordset1['cat_name']; ?>)...how would i write these links and how woudl i update the htaccess file?

 

i think once i understand these bits i should be ok...fingers crossed. Thanks in advance

 

Link to comment
https://forums.phpfreaks.com/topic/167394-seo-friendly-link/#findComment-883784
Share on other sites

ok, i had a 'play' yesterday....without any problems, but a couple of questions.

 

as a update, links are as;

 

<a href="whatson_detail/<?php echo $row_Recordset1['event_id']; ?>/<?php echo $row_Recordset1['cat_name']; ?>/<?php echo $row_Recordset1['event_name']; ?>.html"

 

andf the htacces file is;

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
rewriterule ^whatson_detail/([^-]+)/([^&]+)\.html$ /whatson.php?event_id=$1&cat_name=$2&event_name=$3 [L]
</IfModule>

(the event name $3 isnt important as passed variable, so i left it out)

 

The reason why is because you only have two possible matches in your rewrite rule. This is why I suggested you to use the following instead

rewriteRule ^whatson/([0-9+])/([A-Z0-9_]+)/([A-Z0-9_]+).html$ /whatson.php?event_id=$1&cat_name=$2&event_name=$3 [NC,L]

 

In order for you to understand whats happing in your rewriterule you need to know the basic syntax for regex (regular expressions). Each possible match is wrapped in parenthesis (). Here is a basic visual representation

 

Example URL:

mysite.com/whatson/123/cat_name/event_name.html

 

RewriteRule

rewriteRule ^whatson/([0-9+])/([A-Z0-9_]+)/([A-Z0-9_]+).html$ /whatson.php?event_id=$1&cat_name=$2&event_name=$3

 

 

so, questions, questions..

 

If i want to add 2 more links (one to whatson.php and another to whatson.php?<?php echo $row_Recordset1['cat_name']; ?>)...how would i write these links and how woudl i update the htaccess file?

 

i think once i understand these bits i should be ok...fingers crossed. Thanks in advance

 

You need to write separate rewriteRules for each type of url. So if you have the following possible urls

 

mysite.com/whatson/123/cat_name/event_name.html

mysite.com/whatson/123/cat_name.html

mysite.com/whatson/123/

 

You'll have to have the following rules

rewriteRule ^whatson/([0-9+])/([A-Z0-9_]+)/([A-Z0-9_]+).html$ /whatson.php?event_id=$1&cat_name=$2&event_name=$3 [NC,L]
rewriteRule ^whatson/([0-9+])/([A-Z0-9_]+).html$ /whatson.php?event_id=$1&cat_name=$2[NC,L]
rewriteRule ^whatson/([0-9+])/$ /whatson.php?event_id=$1[NC,L]

Link to comment
https://forums.phpfreaks.com/topic/167394-seo-friendly-link/#findComment-884121
Share on other sites

lovely...thanks for your time in explain this to me....very well written and informative.

I was a bit nervous about having numerous whatson rewrites (thinking that they conflict)

 

With reference to the whatson link....would it just be whatson or whatson/

 

many thanks

 

Link to comment
https://forums.phpfreaks.com/topic/167394-seo-friendly-link/#findComment-884138
Share on other sites

  • 4 weeks later...

sorry, i know its an old post, but ive come under a little problem...

 

For example i have this link

<?php $out2 = str_replace(" ", "-", $row_Recordset1['event_name']);  ?><a href="whatson_detail/<?php echo $row_Recordset1['event_id']; ?>/<?php echo $row_Recordset1['cat_name']; ?>/<?php echo $out2?>.html"><?php echo $row_Recordset1['event_name']; ?></a>

 

And ive changed the htaccess file to:

 

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
rewriteRule ^whatson_detail/([0-9+])/([A-Z0-9_]+)/([A-Z0-9_]+)\.html$ /whatson_detail.php?event_id=$1&cat_name=$2&event_name=$3 [NC,L]
rewriteRule ^whatson.html$ /whatson.php [NC,L]
</IfModule>

 

......however i get a page not found.

 

Strangely enough, initially i didnt setup the htacces file correctly (forgot one variable) , however it worked using following htaccess and the inital link (above)

 

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
rewriterule ^whatson_detail/([^-]+)/([^&]+)\.html$ /whatson_detail.php?event_id=$1&cat_name=$2&event_name=$3 [L]
rewriteRule ^whatson.html$ /whatson.php [NC,L]
</IfModule>

 

...... i hope that someone can give me a push in the right direction.

 

thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/167394-seo-friendly-link/#findComment-903301
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.