1

I've made a website, and page links are formed like this: ?page=projects_project1.
I want the pages to be accessible this way as well: projects/project1. So ?page= should be removed, and _ should be replaced by /... So what's being accessed now using ?page=projects_project1, should become accessible at projects/project1...
What do I need to put in my .htaccess file to achieve this? Please also explain how it is done, so I can do it myself next time.

1 Answer 1

1

Try this out:

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^([^/]+)/([a-z0-9_]+)$ index.php?page=$1_$2 [NC,L]

The first line says that it should follow the symbolic links that may exist, the second line actually switches on the RewriteEngine and the third matches links that look like the following:

anything_except_a_forward_slash/anything_here_that_is_an_alphanumeric_or_forward_slash

Sign up to request clarification or add additional context in comments.

15 Comments

... That didn't go too well... Internal Server Error.
Ooops, forgot one of the important keywords - fixed!
Error 310 (net::ERR_TOO_MANY_REDIRECTS): There are too many redirects.
It seems like something is keeping your redirects from ending. Are you manually redirecting in the file that serves your pages?
If $_GET['page'] is empty: header('Location: ?pagina=home');. Can that possibly be the problem?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.