So I have this blog where I have two php files one serves as an index to all my blog posts

the cat value stands for category I have three categories, programming, embedded systems and rant.

I want to change this something like should translate to

and another in the same directory(I can move this to a different directory if I want) which lets me view a particular blog post.

I have indexed each of my blog posts with a number.

Ideally I want this to translate to if 32 is a blog post belonging to 1 category.

Please don't ask me what I have done cause I am not even sure this could be accomplished with PHP alone on a shared host !! I just selected couple of tags that I think are relavant to this.

Foi útil?

Solução - This is a good tutorial.


Find the httpd.conf file for your server and uncomment the following line by removing the #:

# LoadModule rewrite_module modules/mod\ 

Create a file called .htaccess (no name, extension .htaccess) and open it in your code editor of choice and enter the following:

RewriteEngine on

Which enables the rewrite engine obviously. From there you can make rewrite declarations by writing RewriteRule followed by a regular expression that matches the URL you are trying to catch, followed by the URL you want to be "redirected" to, using $1, $2, ... , $n etc to match the bracketed parts of the regex respective of the order they appear in it.

RewriteEngine on

RewriteRule ^/view/([0-9]+)/?$ /view.php?cat=$1

Save that file in the root of your website. Would take and "redirect" to I would suggest reading the article I mentioned above as it covers this practice in far greater detail.

Outras dicas

If I understand you correctly, you could put this in your htaccess file. (assumes Apache)

DirectoryIndex view.php

See this Q&A for reference

If your site automatically goes to index.php, then you might skip this and then in index.php load whatever page/file you want with a conditional include.

None of what I am saying is intended to dispute the re-write answers, just giving alternatives.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top