0

I have a website http://sharenotes.xyz/.
In this website users can save and share quick notes to others users.
There is a unique note id for each note. (id can only contain [0-9A-Za-z_] charachters).
Unique note id is present in the url http://sharenotes.xyz/hithere.
In this case hithere is the unique note id.
In actual the url is like http://sharenotes.xyz/index.php?id=hithere.
My folder structure looks like -
folder structure
and index.php file is present in public folder.
What will be the content of the .htaccess file to short the url from http://sharenotes.xyz/index.php?id=hithere to http://sharenotes.xyz/hithere and in which folder should I place that .htaccess file ?
I know php but I am new in htaccess file (stored in public_html folder).

UPDATE

I was forget to tell you something that -
There is folder named as public which servers all user accessible files. So I have also hide the name public from the url throught .htaccess file.

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule ^$ public/ [L]
  RewriteRule (.*) public/$1 [L]
</IfModule>
Options -Indexes

That's why you wouldn't see public in url.

1 Answer 1

1

This would be the required rewriting rule:

RewriteEngine on
RewriteRule ^/?([0-9a-zA-Z_]+)/?$ /public/index.php?id=$1 [END]

Best is to implement such rules in the actual http server's host configuration. Only if you do not have access to that, then you should use a distributed configuration file, often called ".htaccess". But that comes with a number of disadvantages. If you decide to use one, then place it inside the top folder of your hosts DOCUMENT_ROOT, so here inside the "public_html" folder.

Obviously the rewriting modules needs to be loaded into the apache http server for this. And if you are using a distributed configuration file then you also need to enable the interpretation of such files for that location (read about the AllowOverride directive in the documentation of the http server).

Most likely you will need to add further rewriting rules to sort out requests to other resources.


UPDATE

Considering your comments and the additional information you now added to describe your actual situation this variant probably is close to what you are looking for:

RewriteEngine on

RewriteCond /public%{REQUEST_URI} -f [OR]
RewriteCond /public%{REQUEST_URI} -d
RewriteRule ^ /public%{REQUEST_URI} [END]

RewriteRule ^/?([0-9a-zA-Z_]+)/?$ /public/index.php?id=$1 [END]
Sign up to request clarification or add additional context in comments.

8 Comments

Sorry I forget one thing to mention. So please read my updated section. Then reanswer !
So you need to combine both rule, right? I am sure you will figure that one out...
Indeed. That is true.
the above rule which gives you is not working. 404 error because browser is looking for a file hithere (i guess)
The above rule is working perfectly fine. But now, that your actual situation is actually different you need to adjust it. As said: you need to _combine both rules.
|

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.