0
votes

Is it possible to mask a URL (not redirect) in Codeigniter using a RewriteRule in htaccess rather than using routing inside routes.php?

My goal is to achieve the following:

URL visible to the user --> https://example.com/search/query/page

Actual URL --> https://example.com/search?q=query&p=page

What I've tried so far, with no luck:

In routes.php --> $route["search/(:any)/(:any)"] = "search?q=$1&p=$2";

In .htaccess --> RewriteRule ^search/(.*)/(.*)$ /search?q=$1&p=$2 [NC,L]

I've actually considered migrating the whole application from query strings to URL segments, but unfortunately I'm bound to working with an existing codebase from a client and migrating isn't really an option.

Any help would be much appreciated :)

1

1 Answers

0
votes

try this route:

Options All -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]