Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1808312
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:14:46+00:00 2026-05-17T06:14:46+00:00

We have a PHP app with a dynamic URL scheme which requires characters to

  • 0

We have a PHP app with a dynamic URL scheme which requires characters to be percent-encoded, even “unreserved characters” like parentheses or aphostrophes which aren’t actually required to be encoded. URLs which the app deems to be encoded the “wrong” way are canonicalized and then redirected to the “right” encoding.

But Google and other user agents will canonicalize percent-encoding/decoding differently, meaning when Googlebot requests the page it will ask for the “wrong” URL, and when it gets back a redirect to the “right” URL, Googlebot will refuse to follow the redirect and will refuse to index the page.

Yes, this is a bug on our end. The HTTP specs require that servers treat percent-encoded and non-percent-encoded unreserved characters identically. But fixing the problem in the app code is non-straightforward right now, so I was hoping to avoid a code change by using an Apache rewrite rule which would ensure that URLs are encoded “properly” from the point-of-view of the app, meaning that apopstrophes, parentheses, etc. are all percent-encoded and that spaces are encoded as + and not %20.

Here’s one example, where I want to rewrite the first and end up with the second form:

  • http://www.splunkbase.com/apps/All/4.x/Add-On/app:OPSEC+LEA+for+Check+Point+(Linux)
  • http://www.splunkbase.com/apps/All/4.x/Add-On/app:OPSEC+LEA+for+Check+Point+%28Linux%29

Here’s another:

  • http://www.splunkbase.com/apps/All/4.x/app:Benford’s+Law+Fraud+Detection+Add-on
  • http://www.splunkbase.com/apps/All/4.x/app:Benford%27s+Law+Fraud+Detection+Add-on

Here’s another:

  • http://www.splunkbase.com/apps/All/4.x/app:Benford%27s%20Law%20Fraud%20Detection%20Add-on
  • http://www.splunkbase.com/apps/All/4.x/app:Benford%27s+Law+Fraud+Detection+Add-on

If the app sees only the second form of these URLs, then it won’t send any redirects and Google will be able to index the page.

I’m a newbie with rewrite rules, and it was clear from my read of the mod-rewrite documentation that mod_rewrite does some automatic encoding/decoding which may help or hurt what I want to do, although not sure.

Any advice for rewrite rules to handle the above cases? I’m OK with a rule for each special character since there’s not many of them, but a single rule (if possible) would be ideal.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:14:46+00:00Added an answer on May 17, 2026 at 6:14 am

    The solution actually may be fairly simple, though it will only work in Apache 2.2 and later due to the use of the B flag. I’m not sure whether or not it takes care of every case correctly (admittedly I’m a bit skeptical it doesn’t involve more work than this), but I’m led to believe it should by the source code.

    Keep in mind too that the value of REQUEST_URI is not updated by mod_rewrite transformations, so if your application relies on that value to determine the requested URL, the changes you make won’t be visible anyway.

    The good news is that this can be done in .htaccess, so you have the option of leaving the main configuration untouched if that works better for you.

    RewriteEngine On
    
    # Make sure this is only done once to avoid escaping the escapes...
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    # Check if we have anything to bother escaping (likely unnecessary...)
    RewriteCond $0 [^\w]+
    # Rewrite the entire URL by escaping the backreference
    RewriteRule ^.*$ $0 [B]
    

    So, why is there a need to use the B flag instead of letting mod_rewrite escape the rewritten URL automatically? When mod_rewrite automatically escapes the URL, it uses ap_escape_uri (which apparently has been turned into a macro for ap_os_escape_path for some reason…), a function that escapes a limited subset of characters. The B flag, however, uses an internal module function called escape_uri, which is modeled on PHP’s urlencode function.

    The implementation of escape_uri in the module suggests that alphanumeric characters and underscores are left as-is, spaces are converted to +, and everything else is converted to its escaped equivalent. This seems to be the behaviour that you want, so presumably it should work.

    If not, you do have the option of setting up an external program RewriteMap that could manipulate your incoming URLs into the correct format. This requires manipulating the Apache configuration though, and a renegade script could cause problems for the server on the whole, so I don’t consider it an ideal solution if it can be avoided.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP app which can hook into multiple backends (currently MySQL or
I have a PHP app that creates a CSV file which is forced to
I have a PHP app that I would like to test against various PHP
Does anyone use PhoneGap? I have a php app which uses ajax to receive
i have single php dynamic page that load image each time app user is
I have a web app of which I would like to create a mobile
I have a PHP app which takes a user-inputted $imageurl and does the following:
I have a LAMP (PHP) web app which need to interface with programs on
We have an existing PHP/MySQL app which doesn't have indexes configured correctly (monitoring shows
I have my php app working fine, performing some other Graph API functions. However,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.