删除URL中的.php扩展名

I previously changed my .htaccess file so that my 'subdirectory' (13/) can be the 'directory' I use for my main domain by adding :

RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteRule ^(/)?$ 13/index.php [L]

Now I want to remove the .php extensions and extensions like index.php?eventid=3 to index/something

EDIT#1[where something is the name of that id stored in the database]

How should I do that? Previously, I did work in some PHP-frameworks but they already have a dedicated url file. So I never thought much about it. But this time, I'm not using any framework, so I need to modify .htaccess.

I looked around, but was unable to find any reliable blog/sources.

EDIT #2

My sub-directory is public_html/13/.

ie, www.mydomain.com redirects to www.mydomain.com/13/ Now I want to access www.mydomain.com/13/events.php?eventid=1 as www.mydomain.com/events/44

RewriteRule ^([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)/([0-9]+)/?$ $1.php?$2=$3

The above code would redirect http://www.mydomain.com/index/eventid/3/ to http://www.mydomain.com/index.php?eventid=3

htaccess is very flexible, and creating variations of the above is pretty easy once you understand the syntax. You will want to read up on the regular expressions you can use, and the myriad of options the Rewrite module has to offer. Most of my redirects look like the above though, real simple.

EDIT: An example of what you're looking for is Wordpress, which uses slugs to identify pages based on something more semantic than an ID number. You would have to url encode the name of the item from the database and either store it in the database as the slug, or find some other way of making it usuable in the database query that retrieves the content of the page. Then your htaccess would look something like this:

RewriteRule ^([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)/?$ $1.php?slug=$2

In your PHP you will need to create slugs and store them in the db so they can be used as IDs in your queries.

EDIT2: Try changing your entire htaccess file to just this:

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com$ [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [R=301,L]

RewriteRule ^([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)/([0-9]+)/?$ $1.php?$2=$3

</IfModule>

I have tested it and it works. Something else in your htaccess is messing it up.

Just use the following rule:

 RewriteRule ^index/([0-9]+)/?$ /index.php?eventid=$1 [QSA,L]