skip to Main Content

I’m successfully using mod_rewrite to grab the url and pass it as a parameter but only when the url has a prefix of at least one character.

The .htaccess file is in the directory www.site.com/content

For example, the following Rewrite succeeds: (site.com/content/-seo-friendly-url)

RewriteEngine on
RewriteRule ^content-(.*)$ ./get_content.php?url=$1

but this example does not work: (site.com/content/seo-friendly-url)

RewriteEngine on
RewriteRule ^(.*)$ ./get_content.php?url=$1

I get a 500 Internal Server Error

and this gets a 404 Not Found

RewriteRule ^([a-zA-Z0-9-])$ ./get_content.php?url=$1

and this passes ‘get_content’ as the ($1) parameter to get_content.php with no error

RewriteRule ^(.*)$ get_content.php?url=$1

The goal is to pass the url to get_content.php without a prefix.

For example,

www.site.com/content/seo-friendly-url

should be rewritten to

www.site.com/content/get_content.php?url=seo-friendly-url

2

Answers


  1. try this. I haven’t tested this code, but I’m pretty sure it may help you

    RewriteEngine On

    RewriteRule ^content/get_content.php?url=seo-friendly-url$ /content/seo-friendly-url [L]

    If this didn’t work i recommend to use this site. It helped me with a lot of rewrite’s

    Click this link!

    Login or Signup to reply.
  2. Try this rule,

    RewriteRule ^([w-]+)$ get_content.php?url=$1
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search