Jump to content

read more links...blog posts


jimfog

Recommended Posts

I have observed that read more links of blog articles in Wordpress have this user friendly form:

https://domain.gr/2016/04/26/easter-holidays/

For the date part I am not sure...probably it is optional

I do not use Wordpress....I make a custom blog and I want my read more links to have the same form.

How am I going to achieve this?

Furthermore I do not see some kind of ID in the url that will aid in retrieving the article from the Database.
So there is this issue too.

 

The only thing that I can think of is that the title of the article is used to retrieve the article from the database.

 

What do you think?

Link to comment
Share on other sites

  • Replies 71
  • Created
  • Last Reply

Top Posters In This Topic

You have option to use ugly url would use post/page id, alias url which would be category it belongs and title striped of small common words 'of', 'it' etc to leave url best for seo purposes related to post/page Or a custom alias. Together with mod_rewrite code the new friendly url is forced to show when ugly url is used.

Link to comment
Share on other sites

.... new friendly url is forced to show when ugly url is used.

I do not quite understand what do you mean with the above

Link to comment
Share on other sites

The string "easter-holidays" is probably a unique identifier for the article.

so...you are saying that the retrieval of the article from the database is based on this unique-identified.

Are you assuming this is the case or you know it?

Link to comment
Share on other sites

By default what is called a ugly link, is a link that uses a id ref for post like http://example.com/index.php?post=49 where 49 is the post table id of content stored in database, you can alter the cms settings so that url is more seo friendly (ie a prettier link), by using the title for a rough example, with <h1>header of post for seo friendly link</h1> the url will become

http://example.com/header-post-seo-friendly-link/ this url can also can customized further using plugin the ugly can still be used but will usually using mod_rewrite in php to convert to the newer what is called more seo friendly link.

Link to comment
Share on other sites

I do not use a CMS so the idea of a plugin is not suitable here.

regarding mod_rewrite...

 

I do not know how to use it...especially in this case.

 

For example...the link in the HTML file(that the user will click) is it going to be in the user-friendly form and then transformed to the "dirty" form by mod_rewrite?

I do not want to go further...answer this for now.

Link to comment
Share on other sites

I'm just explaining HOW Wordpress which YOU mentioned which IS a CMS works, that could involve the use of a plugin depending on the url required, now it is for YOU, to attempt to recreate, the same result now I've explained what it involves.

Link to comment
Share on other sites

I'm just explaining HOW Wordpress which YOU mentioned which IS a CMS works, that could involve the use of a plugin depending on the url required, now it is for YOU, to attempt to recreate, the same result now I've explained what it involves.

I suppose you mean that the issue now is for a different topic.

Link to comment
Share on other sites

The blog will still have id ref, but you have dynamically produce a more unique friendly link by use separating by category type, with date as in year/month/day or include title separated by hyphens which will produce some like http://example.com/index.php?post=49&cat=whatever&date=2016-04-26&title=whatever-dude

 

mod_rewrite can take this ugly url to give you an friendly url in address bar of

 

http://example.com/whatever/2016-04-26/whatever-dude

 

You can even add www or add suffix of .html

 

http://www.example.com/whatever/2016-04-26/whatever-dude.html

 

So you have sort out the best pattern of this querystring so mod_rewrite can produce the url you require.

Edited by dsonesuk
Link to comment
Share on other sites

I am going to ask again...so I can have it clear in my mind.

The link in the HTML file is it going to be dirty?

 

If the user views the source of the file what URL will be there...forger mod_rewrite for a second and what is displayed in the address bar.

 

You are describing me the end result....before reaching there I am trying to understand it step by step.

 

And if you are wondering why I am insisting so much take a look at the read more links here https://taxibeat.com/blog/

Link to comment
Share on other sites

Rough example

page1.php

<!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title></title>    </head>    <body>        <?php        echo '<h1>' . $_GET['country'] . '</h1>';        echo '<h2>' . $_GET['state'] . '</h2>';        echo '<h3>' . $_GET['city'] . '</h3>';        ?>        <p>    <a href="http://localhost/page1.php?country=USA&state=California&city=San_Diego">http://localhost/page1.php?country=USA&state=California&city=San_Diego</a></p>        <p>            <a href="http://localhost/USA/California/San_Diego">http://localhost/USA/California/San_Diego</a>        </p>    </body></html>
.htaccess

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteBase /

# test that base is correct and rewrite is working by creating 2 test files one html the other php with header to reflect file type
# opening show html file should show php file header even though URL still shows html
RewriteRule ^/?test.html$ test.php [L] 

# --------------------------------------------------------------------------------empty querystring -------------------------------------------------------------------
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(/|page1.php)?$ page1.php?country=No&state=Where&city=Land [R=301,L]
#  ------------------------------------------------------------------------------------------------------------------------------------------------------------------------


# -------------------------------------------------------if ugly link entered or selected read querystring values-------------------------------------------
# retrieve query string values
RewriteCond %{QUERY_STRING} ^country=([^/]*)&state=([^/]*)&city=([^/]*)

# prevent rewrite loop by checking for noredirerect query string when attempting to 301 redirect the ugly URL
RewriteCond %{QUERY_STRING} !noredirect=

# Rewrite url with friendlier URL
RewriteRule ^page1\.php %1/%2/%3? [L,R=301]
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------


# ---------------------read friendlier selected or entered link and link to uglier URL in background --------------------------------------
#-------------------------------------------while showing friendlier link in address bar------------------------------------
RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z_]+)/([a-zA-Z_]+)$ page1.php?country=$1&state=$2&city=$3&noredirect=no [L]
#-----------------------------------------------------------------------------------------------------------------------------
</IfModule>
Edited by dsonesuk
Link to comment
Share on other sites

before continuing and testing the code I want to know where I should place .htaccess?

Inside htdocs or inside the project folder(which is inside htdocs)?

Link to comment
Share on other sites

You should able to place under the root directory, but I should place it under the same location as php file, if you place file in subfolder of root directory the rewriteBase should reflect that path (/subfolder/), try the test first ( test.html and test.php) where you open test.html but it actually shows test.php content even though url shows html in address bar.

 

Every time you make adjustment to .htaccess file clear all private data/history close php/html file and reopen, it tends to stick with previous .htaccess admendment otherwise.

Link to comment
Share on other sites

You should able to place under the root directory, but I should place it under the same location as php file,

to which PHP file are you referring to...test.php

Link to comment
Share on other sites

I cannot make .htaccess work...inside it I have placed this redirection syntax

Redirect 301 /genga.php http://www.example.org/newpage.html

this is the link I click

http://localhost/Appointments/Frontend/blog_dtl/genga.php

 

And here is the dir structure where I indicate the folder where this .htaccess is located

https://onedrive.live.com/redir?resid=BE27434B2AAC8130!454&authkey=!AO71ww8Tkksk6hc&v=3&ithint=photo%2cPNG

 

I always restart Apache...

 

I do not know what is wrong....

Link to comment
Share on other sites

Did you change RewriteBase to reflect the path to your folder?

 

#first slash represents root directory http://localhost/

RewriteBase /Appointments/Frontend/

here is my htaccess file after modifying it according to the above.


RewriteBase /Appointments/Frontend/ 
Redirect 301 /blog_dtl/genga.php http://www.example.org/newpage.html

Still nothing....no redirection takes place.

Edited by jimfog
Link to comment
Share on other sites

The redirect you are using is nothing to do with the mod rewrite code, mixing the two will cause it to fail, that simpler redirect which I TOLD YOU NOT TO INCLUDE YET! Should be placed above the opening tag that contain and will run mod rewrite code.

 

Add nothing else, get it! Do the test.php/html first get it to work, try page1.php with 3 query string, see how that works before going any further. You also mentioned nothing about clearing cache/history. Failing to do THIS evertime you make an amendment to .htaccess means your results won't truly refect current change and probably give impression it did not work, whereas it probably would have, you then amend it again wrongly and end up going round and round in circles.

Link to comment
Share on other sites

The redirect you are using is nothing to do with the mod rewrite code, mixing the two will cause it to fail, that simpler redirect which I TOLD YOU NOT TO INCLUDE YET! Should be placed above the opening tag that contain and will run mod rewrite code.

 

Add nothing else, get it! Do the test.php/html first get it to work, try page1.php with 3 query string, see how that works before going any further. You also mentioned nothing about clearing cache/history. Failing to do THIS evertime you make an amendment to .htaccess means your results won't truly refect current change and probably give impression it did not work, whereas it probably would have, you then amend it again wrongly and end up going round and round in circles.

 

One by one:

I know that the redirect has nothing to do mod_rewrite...I do not mix them...here is the file as we speak:


RewriteBase /Appointments/Frontend/ 
Redirect 301 /blog_dtl/genga.php http://www.example.org/newpage.html

You mean I should clear the browser cache?You are right I did not try that.

I suppose browser history will be gone...

confirm this please before continuing

Link to comment
Share on other sites

this is the latest iteration:

RewriteBase /Appointments/Frontend/ 
Redirect 301 /test.html /test.php

no redirection takes place...and yes I cleared the browser cache.

Link to comment
Share on other sites

What!

One by one:

I know that the redirect has nothing to do mod_rewrite...I do not mix them...here is the file as we speak:

 

RewriteBase /Appointments/Frontend/ Redirect 301 /blog_dtl/genga.php http://www.example.org/newpage.html
This just shows that YOU ARE MIXING NON mod rewrite code, check my original code, WHERE do you see

'Redirect 301 /blog_dtl/genga.php http://www.example.org/newpage.html' I will tell YOU! NOWHERE!

 

Any of these non mod rewrite redirecting code SHOULD NOT appear between <IfModule mod_rewrite.c> and </IfModule> tags

Edited by dsonesuk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...