Connecting Tech Pros Worldwide Help | Site Map

Help with mod_rewrite

  #1  
Old October 18th, 2006, 09:55 PM
Hermann.Richter@gmail.com
Guest
 
Posts: n/a
I want to rewrite URLs like
http://domain/dir/file.php?var1=val1&var2=val2#anchor

to
http://domain/dir/file?var1=val1&var2=val2#anchor

In other words, I want to strip out the php extension

I tried putting in the .htaccess file the following:

DefaultType application/x-httpd-php

But that didn't work at all.

So I tried with mod_rewrite:

RewriteRule /[^/\.]+$ %{REQUEST_FILENAME}.php

It doesn't work either!!!

I need help please. What is the problem??

My hosting server is apache 1.3.37


Thanks in advance.

  #2  
Old October 19th, 2006, 03:25 AM
petersprc@gmail.com
Guest
 
Posts: n/a

re: Help with mod_rewrite


Hi,

You could use the ForceType directive to serve PHP URLs without a file
extension. For example:

<FilesMatch "^[^\.]*$">
ForceType application/x-httpd-php
</FilesMatch>

That would treat every file with no extension as a PHP script. On disk
the file path could be "/dir/file", and the URL would be "/dir/file".

Not sure if that's what you wanted. You can also use mod_rewrite in
this scenario. For example:

RewriteEngine On
RewriteRule ^([^\.\?]+)(\?.*)?$ $1.php$2

That would internally convert incoming URLs that lacked a file
extension into .php requests. It would convert "file?a=b" into
"file.php?a=b". You would then create a script called file.php.

I think the ForceType way is probably easier. Is that what you needed?

Hermann.Richter@gmail.com wrote:
Quote:
I want to rewrite URLs like
http://domain/dir/file.php?var1=val1&var2=val2#anchor
>
to
http://domain/dir/file?var1=val1&var2=val2#anchor
>
In other words, I want to strip out the php extension
>
I tried putting in the .htaccess file the following:
>
DefaultType application/x-httpd-php
>
But that didn't work at all.
>
So I tried with mod_rewrite:
>
RewriteRule /[^/\.]+$ %{REQUEST_FILENAME}.php
>
It doesn't work either!!!
>
I need help please. What is the problem??
>
My hosting server is apache 1.3.37
>
>
Thanks in advance.
  #3  
Old October 19th, 2006, 03:35 AM
Hermann.Richter@gmail.com
Guest
 
Posts: n/a

re: Help with mod_rewrite


That's exactly what I need.

But I dont have access to httpd.conf, so it mut be done on .htaccess
files.

The fileMatch tag can be on a .htaccess file??



petersprc@gmail.com wrote:
Quote:
Hi,
>
You could use the ForceType directive to serve PHP URLs without a file
extension. For example:
>
<FilesMatch "^[^\.]*$">
ForceType application/x-httpd-php
</FilesMatch>
>
That would treat every file with no extension as a PHP script. On disk
the file path could be "/dir/file", and the URL would be "/dir/file".
>
Not sure if that's what you wanted. You can also use mod_rewrite in
this scenario. For example:
>
RewriteEngine On
RewriteRule ^([^\.\?]+)(\?.*)?$ $1.php$2
>
That would internally convert incoming URLs that lacked a file
extension into .php requests. It would convert "file?a=b" into
"file.php?a=b". You would then create a script called file.php.
>
I think the ForceType way is probably easier. Is that what you needed?
>
Hermann.Richter@gmail.com wrote:
Quote:
I want to rewrite URLs like
http://domain/dir/file.php?var1=val1&var2=val2#anchor

to
http://domain/dir/file?var1=val1&var2=val2#anchor

In other words, I want to strip out the php extension

I tried putting in the .htaccess file the following:

DefaultType application/x-httpd-php

But that didn't work at all.

So I tried with mod_rewrite:

RewriteRule /[^/\.]+$ %{REQUEST_FILENAME}.php

It doesn't work either!!!

I need help please. What is the problem??

My hosting server is apache 1.3.37


Thanks in advance.
  #4  
Old October 19th, 2006, 04:35 AM
petersprc@gmail.com
Guest
 
Posts: n/a

re: Help with mod_rewrite


Yep, ForceType can be used in .htaccess. (Not sure if AllowOverride
needs to include FileInfo?)

Hermann.Richter@gmail.com wrote:
Quote:
That's exactly what I need.
>
But I dont have access to httpd.conf, so it mut be done on .htaccess
files.
>
The fileMatch tag can be on a .htaccess file??
>
>
>
petersprc@gmail.com wrote:
Quote:
Hi,

You could use the ForceType directive to serve PHP URLs without a file
extension. For example:

<FilesMatch "^[^\.]*$">
ForceType application/x-httpd-php
</FilesMatch>

That would treat every file with no extension as a PHP script. On disk
the file path could be "/dir/file", and the URL would be "/dir/file".

Not sure if that's what you wanted. You can also use mod_rewrite in
this scenario. For example:

RewriteEngine On
RewriteRule ^([^\.\?]+)(\?.*)?$ $1.php$2

That would internally convert incoming URLs that lacked a file
extension into .php requests. It would convert "file?a=b" into
"file.php?a=b". You would then create a script called file.php.

I think the ForceType way is probably easier. Is that what you needed?

Hermann.Richter@gmail.com wrote:
Quote:
I want to rewrite URLs like
http://domain/dir/file.php?var1=val1&var2=val2#anchor
>
to
http://domain/dir/file?var1=val1&var2=val2#anchor
>
In other words, I want to strip out the php extension
>
I tried putting in the .htaccess file the following:
>
DefaultType application/x-httpd-php
>
But that didn't work at all.
>
So I tried with mod_rewrite:
>
RewriteRule /[^/\.]+$ %{REQUEST_FILENAME}.php
>
It doesn't work either!!!
>
I need help please. What is the problem??
>
My hosting server is apache 1.3.37
>
>
Thanks in advance.
  #5  
Old October 19th, 2006, 08:35 AM
rh
Guest
 
Posts: n/a

re: Help with mod_rewrite



<Hermann.Richter@gmail.comwrote in message
news:1161205984.787026.311810@m73g2000cwd.googlegr oups.com...
Quote:
I want to rewrite URLs like
<snip>
Quote:
My hosting server is apache 1.3.37
It's an Apache server question, not PHP

Read the Apache docs for Options (Content negotiated MultiViews).

Options +MultiViews


Rich


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
mod_rewrite index.php theoni answers 2 June 3rd, 2009 10:08 AM
Multi language site with PHP, mysql and cookies - how about search engines? CAH answers 7 April 11th, 2007 07:55 AM
Problem with mod_rewrite and replacing spaces in URL David answers 2 October 18th, 2006 06:45 PM
Help with string replace... Tihon answers 7 July 17th, 2005 03:58 AM