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 3319032
In Process

The Archive Base Latest Questions

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

I am trying to use PHP mod_rewrite to alter some URLs. As a test,

  • 0

I am trying to use PHP mod_rewrite to alter some URLs.

As a test, in my .htaccess I have the following:

RewriteEngine on
RewriteRule ^(.*[^/])$ index.php?test=$1
#RewriteRule ^([^/]+)/$ index.php?test=$1

In my index.php file I have simply

<?php print_r($_GET) ?>

What I would like to happen is that when either mysite.com/test or mysite.com/test/ is in the browser address bar, the PHP $_GET[‘test’] variable has the value ‘test’ in it.

The commented line works fine with mysite.com/test/ but seems to do nothing with mysite.com/test

The second line (the uncommented one) results in a value of ‘index.php’ for $_GET[‘test’] when viewing mysite.com/test and doesn’t do anything with mysite.com/test/

Is there anything I’m overlooking here that will allow me to get the desired results?

Thanks

  • 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-17T22:46:37+00:00Added an answer on May 17, 2026 at 10:46 pm

    Try this:

    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*?)/?$ index.php?test=$1
    

    Note for *? quantifier, which declares * to be ungreedy

    http://www.troubleshooters.com/codecorn/littperl/perlreg.htm#Greedy

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

Sidebar

Related Questions

I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I trying to use PHP's file upload abilities, but when I try to upload
Im trying to use the following PHP to add a favorite to my account:
I've been trying to use SQLite with the PDO wrapper in PHP with mixed
While trying to use LINQ to SQL I encountered several problems. I have table
I'm trying to use svnmerge.py to merge some files. Under the hood it uses
I'm trying to use mod_rewrite to handle an unknown number of variables. An example
I am trying to use SEO-friendly URLs for a website. The website displays information
I am trying to use PHP preg_math parse a string that looks like: 6.15608128
I'm trying to use PHP to do this: <if !empty($list) {echo . . .

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.