Solved

How to htaccess rewrite without php extension

Posted on 2009-07-13
16
467 Views
Last Modified: 2012-05-07
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.

RewriteRule (.*)\/ $1.php

Open in new window

0
Comment
Question by:Johan85
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
16 Comments
 
LVL 9

Expert Comment

by:Graceful_Penguin
ID: 24839480
Try this code
RewriteBase /  command should be on if the htaccess file is not in root.

RewriteEngine on
RewriteBase /de
 
RewriteCond %{REQUEST_FILENAME} !(index\.php)
RewriteRule (.*)\/ $1.php

Open in new window

0
 
LVL 1

Author Comment

by:Johan85
ID: 24839655
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

Open in new window

0
 
LVL 9

Expert Comment

by:Graceful_Penguin
ID: 24846840
What was the URL that you used, also could you tell me the in which directory the .htaccess file is.
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 1

Author Comment

by:Johan85
ID: 24846897
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

Open in new window

0
 
LVL 9

Accepted Solution

by:
Graceful_Penguin earned 500 total points
ID: 24847059
Try this
RewriteEngine on
 
RewriteCond %{REQUEST_FILENAME} !(index\.php)
RewriteRule (.*)\/(.*) $1/$2.php

Open in new window

0
 
LVL 1

Author Comment

by:Johan85
ID: 24847084
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
0
 
LVL 9

Expert Comment

by:Graceful_Penguin
ID: 24847190
I forgot the escape chars
RewriteCond %{REQUEST_FILENAME} !(index\.php)
RewriteRule (.*)\/(.+) $1\/$2\.php

Open in new window

0
 
LVL 1

Author Comment

by:Johan85
ID: 24847241
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.
0
 
LVL 9

Expert Comment

by:Graceful_Penguin
ID: 24847487
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.
0
 
LVL 1

Author Comment

by:Johan85
ID: 24847562
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.
0
 
LVL 9

Expert Comment

by:Graceful_Penguin
ID: 24848044
Sorry I wanted to add your url into the rule but forgot it should be
RewriteRule ^index.php$ http://www.campinggroenewoud.nl
and this for the language dirs

RewriteEngine on
RewriteBase /dirname
RewriteRule (.*)\/ $1.php  
0
 
LVL 1

Author Comment

by:Johan85
ID: 24867980
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.
0
 
LVL 9

Expert Comment

by:Graceful_Penguin
ID: 24868399
I don't know ehat is wrong because it is working on my server. maybe you should try to escape all the fullstops.
0
 
LVL 1

Author Comment

by:Johan85
ID: 24869074
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.
0
 
LVL 1

Author Comment

by:Johan85
ID: 24869101
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
0
 
LVL 9

Expert Comment

by:Graceful_Penguin
ID: 24870072
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
 
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question