used colons for url htaccess http://localhost/1:1

Solution 1:

There are a few issues here...

  1. In a per-directory .htaccess context, the URL-path matched by the RewriteRule pattern never starts with a slash, so the regex ^/(.*):(.*) will never match and the directive does nothing. So, the RewriteRule pattern would need to be ^(.*):(.*) - no slash prefix.

    • However, this regex is very general and is most probably matching too much. If you are expecting a request of the form /1:1, ie. /<number>:<number> then use a more specific regex, eg. ^\d+:\d+$
  2. Since you are getting a 403 Forbidden (as opposed to a 404 Not Found) I assume you are on a Windows server. The "problem" here is that : (colons) are not valid characters in Windows filenames. This is an issue with .htaccess because the request is mapped to the filesystem before .htaccess (and mod_rewrite) is processed - at which point the 403 is triggered. You would need to rewrite the request in the main server config (or VirtualHost container) instead - which occurs before the request is mapped to the filesystem.

So, what you are trying to do... rewrite the request that contains a colon, using .htaccess on a Windows server is not possible. You can do this on Linux (that permits colons in filenames) OR in the main server config (server or virtualhost context) on Windows, but not in .htaccess.

When using mod_rewrite in a server (or virtualhost) context (as opposed to .htaccess) you do need the slash prefix (on both the pattern and substitution strings). For example:

# In a "server" (or "virtualhost") context,
#   not ".htaccess" (or "<Directory>" section in the server config)

RewriteEngine On

# Internally rewrite "/1:1" to path-info on "index.php"
RewriteRule ^/\d+:\d+$ /index.php$0 [L]

The $0 backreference contains the entire URL-path that is captured by the RewriteRule pattern. This includes the slash prefix (when used in a server context), which is why the slash delimiter is omitted in the substitution string.


UPDATE:

I made the changes, please look at my question again and see, I entered it correctly

<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot "${INSTALL_DIR}/www"
  <Directory "${INSTALL_DIR}/www/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride all
        Order Allow,Deny
        Allow from all
  </Directory>
</VirtualHost>

You don't seem to have made any changes; at least not in the right section? As mentioned above, these directives need to be added directly to the <VirtualHost> container (that you have posted). They cannot be added to the .htaccess file on a Windows OS - they simply won't do anything and you'll get the 403 Forbidden response as stated.

The above should be written like this:

<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot "${INSTALL_DIR}/www"

  # Enable the rewrite engine in a virtualhost context
  RewriteEngine On

  # Internally rewrite "/1:1" to path-info on "index.php"
  RewriteRule ^/\d+:\d+$ /index.php$0 [L]

  <Directory "${INSTALL_DIR}/www/">
    Options -Indexes -Includes +FollowSymLinks -MultiViews
    AllowOverride all
    Require all granted
  </Directory>
</VirtualHost>

You will need to restart Apache for these changes to take effect. (Unlike .htaccess files that are interpreted at runtime.)

However, what other directives do you have in .htaccess and how are your other URLs being routed? You posted the following directive in comments:

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

This routes the URL quite differently from what you are requesting in your question. In your question you are passing the URL-path as additional path-info to index.php. However, in this directive you are passing the URL as part of the query string? How do these relate? Why are they different? You obviously need to pass the URL in the way your "MVC application" is expecting.