php.htaccessmod-rewriteurl-rewritingpretty-urls

.htaccess Pretty URLs title in url


I'm trying to make pretty url but want to put content title in url instead id, then i put content title in url with query string:

index.php?action=content&id=22

changed to:

index.php?action=content&title=stack-over-flow

it's works fine. now i trying to make it pretty but got a problem in htaccess code.

before removing id in url code was:

RewriteRule ^([a-z]+)/([0-9]+)/?$ index.php?action=$1&id=$2 [NC,L,QSA]

then i changed to:

RewriteRule ^([a-z]+)/([a-z]+)/?$ content.php?action=$1&title=$2 [NC,L,QSA]

but it's not working and i will back 300 Multiple Choices page. well, i think it's a httaccess problem, but i'm new in htaccess, need a hand to fix this.

want this:

/content/stack-over-flow


Solution

  • Your regex is only allowing letters. It should also allow hyphen, numbers, upper case letters and underscore. Try this:

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([a-z]+)/([^/]+)/?$ content.php?action=$1&title=$2 [NC,L,QSA]