How to rewrite dynamic URL?

How to rewrite dynamic URL to SEO Friendly URL?

  • I tried everything I see here in this site to rewrite dynamic url to SEO friendly URL. Is it maybe because im using it in the localhost? I try this but does not work also: RewriteCond %{THE_REQUEST} ^GET\ /index\.php/?([^ ]*) RewriteRule ^index\.php/?(.*) /$1 [R,L] RewriteCond $0 !^index\.php($|/) RewriteRule .* index.php/$0 [L] I also refer to an online dynamic url generator , but it doesn't work either. Please help. I would like to rewrite these couple of URLs: index.php?p=home index.php?p=about me index.php?p=contact me

  • Answer:

    You can use this one: RewriteEngine on RewriteBase / # Rewrite URLs of the form 'x' to the form 'index.php?q=x'. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?q=$1 Then on your index.php page, all the variables will put accessible via $_GET['q']. If you further use $location=array_filter(explode('/',$_GET['q'])); then $location will be an array containing each directory, so www.mysite.com/firstdir/seconddir/thirddir will have $location[0] as 'firstdir' and $location[1] as 'seconddir' and so on. You could then compare these to url_aliases in your database to determine what content/template to display. This also works for localhost for me, except I change the base url part from "/" to "/mycurrentconstructionsite/" Hope that helps!

milagro at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.