1

Possible Duplicate:
Removing .php extension in URLs

I've changed the sub-directory of my public_html to act as the main-directory. Currently, mysite.com/alpha/index.php redirects as mysite.com. This is working perfectly.

Similarly, I have another file events.php, i.e., mysite.com/alpha/events.php?eventid=10 corresponds to mysite.com/events.php?eventid=10

But, I wanted to access the above path as mysite.com/events/10/ instead of mysite.com/events.php?eventid=10. For this I again modified the file, but it fails to load the dynamic URLs. For example, when I hover my mouse on links, it shows

`mysite.com/events/14` 
`mysite.com/events/15` 
`mysite.com/events/16` 
`mysite.com/events/17`

etc. [which is what I want] But on clicking it [If I click on the link that showed mysite.com/events/14 on hover], it opens a page mydomain.com//alpha/events.php/14/14?eventid= and page fetches nothing from the sql tables.

My .htaccess file:

# .htaccess main domain to subdirectory redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change this line.
RewriteEngine on
RewriteRule ^([A-Za-z0-9\-]+)/([0-9]+)/?$ $1.php?eventid=$3
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/alpha/
# Don't change these line.'
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /alpha/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteRule ^(/)?$ alpha/index.php [L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Community
  • 1
  • 1
xan
  • 4,640
  • 13
  • 50
  • 83
  • @TomWalters: That question was also posted by me. That was to remove the `.php` extension and it did. This was to correct `sql` fetching as I was facing difficulty regarding it. – xan Jan 21 '13 at 20:35
  • I don't think this question has any relation to SQL – Ruslan Osipov Jan 21 '13 at 20:36

1 Answers1

1

Line 7 of your apache config should be more like:

RewriteRule ^([A-Za-z0-9\-]+)/([0-9]+)/?$ $1.php?eventid=$2 [L]
Ruslan Osipov
  • 5,655
  • 4
  • 29
  • 44
  • The `sql` fields are shown now, though the URL in the address bar still : `http://www.tryst-iitd.com//13/events.php?eventid=25` – xan Jan 21 '13 at 20:41
  • Apache doesn't change URL in your case, it just rewrites it. You do compose wrong URL in some other place. – Ruslan Osipov Jan 21 '13 at 20:49