By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,130 Members | 2,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,130 IT Pros & Developers. It's quick & easy.

Help with mod_rewrite

P: 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.

Oct 18 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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?

He*************@gmail.com wrote:
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.
Oct 19 '06 #2

P: n/a
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??

pe*******@gmail.com wrote:
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?

He*************@gmail.com wrote:
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.
Oct 19 '06 #3

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

He*************@gmail.com wrote:
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??

pe*******@gmail.com wrote:
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?

He*************@gmail.com wrote:
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.
Oct 19 '06 #4

P: n/a
rh

<He*************@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
I want to rewrite URLs like
<snip>
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
Oct 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.