Johan85
asked on
How to htaccess rewrite without php extension
Hi,
I want to rewrite http://www.mywebsite.com/de/contact.php to http://www.mywebsite.com/de/contact/ So without the .php extension
I also have some link refering to index.php. fi http://www.mywebsite.com/index.php
I want that also rewrited as http://www.mywebsite.com/
I had the following but that didn't seem to do the job.
I want to rewrite http://www.mywebsite.com/de/contact.php to http://www.mywebsite.com/de/contact/ So without the .php extension
I also have some link refering to index.php. fi http://www.mywebsite.com/index.php
I want that also rewrited as http://www.mywebsite.com/
I had the following but that didn't seem to do the job.
RewriteRule (.*)\/ $1.php
ASKER
I tested it and I got this error
Not Found
The requested URL /de.php was not found on this server.
Apache/2.2.3 (CentOS) Server at www.campinggroenewoud.nl Port 80
What was the URL that you used, also could you tell me the in which directory the .htaccess file is.
ASKER
I used the code below. The .htaccess is in the root directory (I removed the RewriteBase command). I get the error message with all URLs. One of the url's I tested is http://tinyurl.com/ly994t
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !(index\.php)
RewriteRule (.*)\/ $1.php
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I get this message
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Apache/2.2.3 (CentOS) Server at www.campinggroenewoud.nl Port 80
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Apache/2.2.3 (CentOS) Server at www.campinggroenewoud.nl Port 80
I forgot the escape chars
RewriteCond %{REQUEST_FILENAME} !(index\.php)
RewriteRule (.*)\/(.+) $1\/$2\.php
ASKER
Sorry, only the index.php pages are working. And it doesn't rewrite /index.php to /
The other pages give the internal server error I mentioned before.
The other pages give the internal server error I mentioned before.
is the language directories actual directories or virtual? If they are actual dirs the best would be to have tree .htaccess files one in root with this command:
RewriteRule ^index.php$ http://www. and then an htaccess file in each of the langauges with therse commands:
RewriteEngine on
RewriteBase /dirname
RewriteRule (.*)\/ $1.php
Not only will this be easier to maintain it would also be better for performance.
RewriteRule ^index.php$ http://www. and then an htaccess file in each of the langauges with therse commands:
RewriteEngine on
RewriteBase /dirname
RewriteRule (.*)\/ $1.php
Not only will this be easier to maintain it would also be better for performance.
ASKER
They are actual directories.
And still not working. The URL's stay the same and some images are not loaded properly with the code above.
And still not working. The URL's stay the same and some images are not loaded properly with the code above.
Sorry I wanted to add your url into the rule but forgot it should be
RewriteRule ^index.php$ http://www.campinggroenewo ud.nl
and this for the language dirs
RewriteEngine on
RewriteBase /dirname
RewriteRule (.*)\/ $1.php
RewriteRule ^index.php$ http://www.campinggroenewo
and this for the language dirs
RewriteEngine on
RewriteBase /dirname
RewriteRule (.*)\/ $1.php
ASKER
I'm still getting the internal server errors, or no rewriting is applied. I have other domains on the same server with succesful rewriting, so I don't know where the problem is.
I don't know ehat is wrong because it is working on my server. maybe you should try to escape all the fullstops.
ASKER
I don't understand either. If I do something like
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.lu [NC]
RewriteRule ^(.*)$ http://www.mysite.lu/$1 [L,R=301]
it works.
But the url rewriting does not happen.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.lu [NC]
RewriteRule ^(.*)$ http://www.mysite.lu/$1 [L,R=301]
it works.
But the url rewriting does not happen.
ASKER
I found this in the error log
[Thu Jul 16 16:04:11 2009] [alert] [client 81.83.8.199] /httpdocs/.htaccess: RewriteCond: bad flag delimiters
[Thu Jul 16 16:04:12 2009] [alert] [client 81.83.8.199] /httpdocs/.htaccess: RewriteCond: bad flag delimiters
[Thu Jul 16 16:04:12 2009] [alert] [client 84.196.202.182] /httpdocs/.htaccess: RewriteCond: bad flag delimiters, referer: http://www.campinggroenewoud.nl/nl/kamperen.php
[Thu Jul 16 16:04:11 2009] [alert] [client 81.83.8.199] /httpdocs/.htaccess: RewriteCond: bad flag delimiters
[Thu Jul 16 16:04:12 2009] [alert] [client 81.83.8.199] /httpdocs/.htaccess: RewriteCond: bad flag delimiters
[Thu Jul 16 16:04:12 2009] [alert] [client 84.196.202.182] /httpdocs/.htaccess: RewriteCond: bad flag delimiters, referer: http://www.campinggroenewoud.nl/nl/kamperen.php
This part of the line is the flags :[L,R=301] can you check all the .htaccess files on your site to see if any of the flags are invalid.
check this site for the flags
http://www.htaccesselite.com/mod-rewrite-flags-vt101.html
check this site for the flags
http://www.htaccesselite.com/mod-rewrite-flags-vt101.html
RewriteBase / command should be on if the htaccess file is not in root.
Open in new window