Hi all,

I am using an apache web server, and this is the raw url:

http://localhost/mysite/index.php?view=contact

how do I convert that to:

http://localhost/mysite/contact/

My current .htaccess is saved in http://localhost/.htaccess, and reads as:

RewriteEngine On
RewriteRule ^mysite/(.*)/$ /mbs/index.php?view=$1 [L]

and I get a 500 internal server error?

Thanks for the help :)

Member Avatar for LastMitch

how do I convert that to:

You can try this:

From this:

RewriteEngine On
RewriteRule ^mysite/(.*)/$ /mbs/index.php?view=$1 [L]

To this:

RewriteEngine On
RewriteRule ^mysite/([^/]*)\.php$ /mbs/index.php?view=$1 [L]

Sorry, still getting the 500 error :S

Member Avatar for LastMitch

Sorry, still getting the 500 error :S

Read this:

http://pcsupport.about.com/od/findbyerrormessage/a/500servererror.htm

Was this an error before the Re Mod?

What else did you put in the htaccess file?

I think there might an issue with a code in htaccess file.

Did you touch anything like a # hash tag on the code?

I mean if the Re Mod is causing the issue then I think you need to rename to this:

RewriteRule ^mysite/(.*)/$ /index.php?view=$1 [L]

Think back what else you did before it was 500 error.

Then you will change it back and not do that again.

The .htaccess file in http://localhost/.htaccess contains:

RewriteEngine On
RewriteRule ^mysite/(.*)/$ /mbs/index.php?view=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]

And there is another file in http://localhost/mbs/.htaccess, containing:

DirectoryIndex index.php

Hope that is any help?

Member Avatar for LastMitch

Take out line 4 to line 6

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]

That will solve the issue.

Leave line 1 and line 2 alone.

It seem like you want to redirect the old links to the new links then do this:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-l
RewriteRule ^/(.*)$  /index.php?view=$1[L,QSA]  

Try to used an Index filename either it's index.php, index.html, index.htm not 1.php

Add this (it's a log in the future if you have an error like this it will tell you which line in the code is producing the error):

RewriteLog /var/log/apache2/rewrite.log
RewriteLogLevel 5    

So this is how it should look like in the end:

RewriteEngine On
RewriteRule ^mysite/([^/]*)\.php$ /mbs/index.php?view=$1 [L]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-l
RewriteRule ^/(.*)$  /index.php?view=$1[L,QSA]  

RewriteLog /var/log/apache2/rewrite.log                                                                             
RewriteLogLevel 5

You will never guess what I just got:

Server error!

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

If you think this is a server error, please contact the webmaster.

Error 500

localhost
03/05/13 17:22:54
Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1

So, erm, yeah :/

I first typed in http://localhost/mysite/, then http://localhost/mysite/contact, the same error for both :S

Member Avatar for LastMitch

Either the server is overloaded or there was an error in a CGI script.

Read this:

http://encodable.com/internal_server_error/

Try this for the Remod:

RewriteEngine On
RewriteRule ^mysite/([^/]*)\.php$ /mbs/index.php?view=$1 [L]
RewriteLog /var/log/apache2/rewrite.log
RewriteLogLevel 5

If you didn't get any error then the error is here from your original code:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]

The code I provide didn't work either because the error still appears.

Then try this now:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?view=$1[QSA,L]

Mod_rewrite needs to be enabled on local host for htaccess to work.

Its an apache server that let htaccess file to run.

commented: Thanks soooo much!!!! Worked perfectly!! :D +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.