• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Rewrite request that matches a pattern

My current .htaccess is this

Apache config:
# ErrorDocument 404 /error/404.php

Options All -Indexes -MultiViews

RewriteEngine On

# Allow urls to not include the .php extension
RewriteCond %{REQUEST_URI}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

# Silent Redirect from any url ending with mcc-* to show.php?id=mcc-*
# This is the portion that isn't working
RewriteCond %{REQUEST_URI} (mcc-[\d]+)\.php$
RewriteCond %{REQUEST_URI}/$1.php -f [NC]
RewriteRule show.php?id=$1 [L]

To make the actual request easier, this is the exact pattern I am looking to rewrite (mcc-[\d]+).
If any url ends with this pattern I want it to instead show show.php?id=%ThePattern%, but only if the url matches this pattern
The answer to this specific question was as follows

Apache config:
RewriteEngine ON

# Allow urls to not include the .php extension
RewriteCond %{REQUEST_URI}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

## Rules for internal rewrite here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(mcc-[\d]+)/?$ show.php?id=$1 [QSA,NC,L]

New Threads

Buy us a coffee!

Top Bottom