Mobile app version of vmapp.org
Login or Join
BetL925

: Rewrite rule to handle urls that start with a slash, have only numbers and letters, and may end with a slash is not working im attempting to get my URL to resolve something like http://example.com/?image=2VMt2

@BetL925

Posted in: #Centos #Htaccess #Php

im attempting to get my URL to resolve something like
example.com/?image=2VMt2

Thus my index.php using the [GET] method in PHP to resolve into my domain
example.com/2VMt2

The rule I am using is stated below.

RewriteEngine on
RewriteRule ^/([A-Za-z0-9-]+)/?$ index.php?image= [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
# 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

</Directory>

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @BetL925

1 Comments

Sorted by latest first Latest Oldest Best

 

@Megan663

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 example.com/2VMt2 and example.com/2VMt2/ URLs will work.

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme