473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Help with mod_rewrite

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
4 2455
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Westcoast Sheri | last post by:
Hello. How do I do this: If a visitor types in any number after my url, I want mod_rewrite to convert it to my url/anotherpage.html?number=number_visitor_typed Example: ...
4
by: Support | last post by:
Hello, I am running RedHat & Apache. RedHat does not allow creating more that 32000 subdirectories in one folder due to #defined constant limitation in the core code. I need to display 47000...
0
by: Molly | last post by:
Peace, Pythonphiles! Python's std lib BaseHTTPServer: I'm stuck with a nasty spoiler -- I get erratic "Network error: disconnected by peer" for _POST_ requests only. =Background= I'm...
6
by: namemattersnot | last post by:
ok. i give up. need help :) here's the rule: RewriteRule ^test/(.+)/(.*)$ /index.php$2 if i request: http://localhost/test/keyword/?show=files it properly redirects me. NOW, if i change...
11
by: joelbyrd | last post by:
I have a people-networking type site in which each user has their own profile page, with their user id encoded. So, for example, the web address of their page might look like...
5
by: laredotornado | last post by:
Hi, I have verified that mod_rewrite is enabled on my Apache 2.2 instance. However, now I'm having a problem just serving pages using .htaccess files. Following Rik's advice, my .htaccess file...
3
by: dennis.sprengers | last post by:
* I'm trying to work out some rewrite rules that should do the following: case 1: a request to mysite.com: rewrite http://www.mysite.com/files/sheets.ppt to...
7
by: Dale | last post by:
again, i know this is OT...just move along to the next post if it bugs you. :) i had been trying to have this: project.66.204.32.110 from the client browser, map to a virtual host where the...
2
by: theoni | last post by:
I need some help with something I am trying to solve here and cannot find anything online I need to mod_rewrite to redirect with 301 to remove duplicate content from google the following: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.