Having Post Name in the url without rewriting current url structure - php

Is it possible to have something like this in wordpress:
http://example.com/post/2135/post-name
without having to rewrite my current url structure which is
http://example.com/post/2135
I want to keep it, and be able to access posts both ways. With and without the post-name
is it possible to have it that way? maybe make wordpress ignore that there's the post name attached at the end?

i believe it is in the php.ini file
example,
me.com/boss
file structure
root/boss/index.php
the index.php file will auto load.
but if you are used MVC you can change the results of what is displayed.
but
can you use http://example.com.post/2135/index.php&postname=lol

Related

cms without view template inside url

I'm creating a simple, wordpresslike cms and keep all parts of a page in a table and load them using a template page named view.php following by a $_GET variable, for example:
sky.com/view.php?article=how-to-do-something
But as I can see on wordpress sites there is no 'view.php' template file and $_GET variables inside url. There is pure domain name and title of an article.
I suppose this is a better approach for SEO engines.
What is the general way to do this and how can I use the same. Is there a function to create a file on fly, or maybe a hidden file system...
The same is with stackoverflow.com. There is no view template inside url, but I'm rather sure it uses database table for storing parts of a page.
I tried with .htaccess file and this accepted solution but got the error 500 - internal server error.
By way of explanation; what stackoverflow.com probably does is something like this:
URL:
https://stackoverflow.com/questions/44654672/cms-without-view-template-inside-url
Actual URL is first rewritten using mod_rewrite so that 1) the missing .php is added, and 2) the GET parameters are set:
RewriteEngine on
RewriteBase /
RewriteRule ^questions/([0-9]+) questions.php?qid=$1 [NC,L]
And so the questions.php page loads the question with id 44654672.
The above mod_rewrite says: take the URL, starting with questions/ and send that URL to questions.php, as well as saying: After questions/ take the number value and use that as the question id GET variable so that the PHP page loads the correct question from the database.
The wording in the URL is purely for SEO purposes.
You will notice that https://stackoverflow.com/questions/44654672 will also load your question correctly (*), but if you change the number value (even while keeping the words the same, ( such as https://stackoverflow.com/questions/44351172/cms-without-view-template-inside-url ) another question will be loaded from the database.
Putting the exact URL link into my answer makes it display the question title rather than URL
Think of it as the mod_rewrite is doing a find and replace search on the URL string. That's all.

Prevent WordPress from removing "/" in URL

Let's say I publish a page in WordPress and it generates a url like this.
mydomain.com/pagestructure
I need to have this structure
mydomain.com/page/structure
I figured several ways of doing that.
Edit url from the page edit screen
Edit permalink structure and use Custom structure there
Edit .htaccess
I can't use the second method because I need this structure only for a single, particular page. Not for all pages.
I can't use third method as it is a bit difficult for me. Sorry for that.
The first method is I want to use as it is the most simpler one. But I am not able to use it because WP does not allow putting "/" at desired places. It re-writes them. If by somehow I prevent the re-writing of "/", maybe via adding a rewrite rule via "add_rewrite_rule", it might solve the problem. Any help?

Creating an SEO friendly url with .htaccess and php from a mysql field

My website creates urls like the following: /index.php?placeid=27
I want to be able to change the url to display the place name, so something like:
/southampton
where the placename is another database field displayed on the content of each page. I guess this requires some php and .htaccess solution which puts a variable into the url, but I can't seem to work this out from any similar questions on here. Thanks.

How to achieve more semantic urls in code igniter?

I am just learning CI. I am trying to build my own CMS. I have successfully created a url structure www.mydomain.com/pages/getpage/2, where 2 is the id of the page.
However, I want to remove the '/pages/getpage/2' from the url. Instead, I want the domain to read www.mydomain.com/about, about being the title of the page, which is a column in the db.
I realise this is something to do with routing and maybe htaccess file.
I'm not sure what to put in routing to make the url as I want it.
If you want www.mydomain.com/pages/getpage/2 to route to www.mydomain.com/about, insert this line in to your routes.php
$route['about/(:num)'] = "pages/getpage/$1";
your URL structure will be www.mydomain.com/about/2, since you need that id as a reference to your content.
visit here for more details on routing

How can I get the value in the URL and modify it for paging with mod-rewrite on?

I am trying to get my old paging class to work which relied on the variables available with $_GET in PHP to reconstruct the URL for the paging links, it worked great but now I am changing to have "pretty url's" with mod-rewrite.
So this
domain.com/?p=the-pagename-identifier&userid=12&page=3
would now be
domain.com/the-pagename-identifier/12/page-3
Problem is my PHP for my old paging would rely on the GET variables to re-construct the URL and make sure any variables present in the URL remain in the new URL's it makes for new pages, now I am stuck because I need it to work with the "virtual" directories that it appears I have in the URL, domain.com/mail/inbox/page-12 is really in the root directory running through my index file domain.com/index.php?p=mail.inbox&page=12
I am lost because some pages will have more things then others in the GET part of the URL.
Since all pages are loaded through the index.php at root level I could almost just link the pages without the full URL path but instead of something like domain.com/mail/page-2 it would end up being domain.com/page-2 since the mail directory in the example is not a real directory. So is it possible to get the value in the URL of a page that was made with mod-rewrite so I can make it think it is in a subfolder and just add the page number onto the current URL of a page?
This rewrite rule:
RewriteRule ^/([0-9a-zA-Z-]+)/([0-9]+)/page-([0-9]+)$ /index.php?p=$1&userid=$2&page=$3
Would transform this:
domain.com/the-pagename-identifier/12/page-3
Into this:
domain.com/?p=the-pagename-identifier&userid=12&page=3
Completely transparent to the end user.
So aside from generating new URL's, your application need not change at all.

Categories