im attempting to get my URL to resolve something like


Thus my index.php using the [GET] method in PHP to resolve into my domain


The rule I am using is stated below.

RewriteEngine on
RewriteRule    ^/([A-Za-z0-9-]+)/?$    index.php?image=$1    [NC,L]

Im running CentOS and my Configuration looks something like the following.

# This should be changed to whatever you set DocumentRoot to.
<Directory "/var/www/html">

# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
    Options Indexes FollowSymLinks

# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
    AllowOverride All

# Controls who can get stuff from this server.
    Order allow,deny
    Allow from all


1 Answer 1


Your server configuration seems to be correct.

But you need to modify your mod_rewrite code. Remove leading / and make trailing slash optional by using /?$ in rewrite rule, so both http://example.com/2VMt2 and http://example.com/2VMt2/ URLs will work.

RewriteEngine on
RewriteRule    ^([A-Za-z0-9-]+)/?$    index.php?image=$1    [NC,L]
  • Thank you very much, I was completing the .htaccess in the wrong folder in my previous comment, haha.
    – John
    Jan 25, 2015 at 6:46
  • (I assume the ^^ and $$ is a copy/paste typo?) In fact, if this is in .htaccess then the preceding / can simply be removed. Also, if you are substituting a relative path then you should use a RewriteBase directive, or better, don't use relative paths.
    – MrWhite
    Jan 25, 2015 at 12:42
  • @w3d no it's not a typo. But you are right, the preceding / isn't actually required here. Jan 25, 2015 at 13:55
  • So... if it's not a typo, it's a deliberate mistake?
    – MrWhite
    Jan 25, 2015 at 14:44
  • 1
    ohh.. now I understand. You are right $$ is also not required, single $ is enough here. Thanks again for pointing that out. Jan 25, 2015 at 15:21

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.