0

I have short url service for a site, which has url like http://example.co?c=xyz. In index.php file parameter is being accessed as $code = $_GET["c"];.

I want to access the same code when i type http://eaxample.co/xyz

.htaccess file config

Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteRule (.*) /$1? [R=301, L]

Can anyone please help me to get right rule?

2 Answers 2

1

Put this code in your DOCUMENT_ROOT/.htaccess file:

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ /?c=$1 [L,QSA]
Sign up to request clarification or add additional context in comments.

5 Comments

For which URL it is giving 404? Make sure this is in DOCUMENT_ROOT/.htaccess
404 for example.co/SAA. I am sure it is in root. I have only 2 files in root index.php and .htacess only
is SAA is not a file/directory then above rule will internally rewrite that to example.com/?c=SAA Can you load the content using example.com/?c=SAA?
Ok now back to basics. Are you sure .htaccess and mod_rewrite are enabled & working?
I had not added AllowOverride All in virtaulhost file. Thanks.
0

If you want, that query string will be working you must to add QSA flag in yours rewriterule.

When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one. Using the [QSA] flag causes the query strings to be combined.

Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteRule (.*) /$1? [R=301, L, QSA]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.