473,395 Members | 1,584 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,395 software developers and data experts.

php and mod_rewrite?

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 the rule to: RewriteRule ^test/(.+)/(.*)$
/index.php$2&key=$1
it stops working.

i figured out that if i remove ? from $show=files and change the rule
to redirect to /index.php?$2, then i can use &key=$1. but i want to
figure out how to redirect the ?show=files request AND at the end add
&key=$1

thanks in advance!

Feb 2 '06 #1
6 1733
hi hru? im balaji. i have one big problem. Full details of
mod_rewrite() value in php with sample example give(plz) me. now one
small idea but most of process i can undrstand plz help me. plz tell me
soon .
na************@msn.com wrote:
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 the rule to: RewriteRule ^test/(.+)/(.*)$
/index.php$2&key=$1
it stops working.

i figured out that if i remove ? from $show=files and change the rule
to redirect to /index.php?$2, then i can use &key=$1. but i want to
figure out how to redirect the ?show=files request AND at the end add
&key=$1

thanks in advance!


Feb 2 '06 #2
na************@msn.com wrote:
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 the rule to: RewriteRule ^test/(.+)/(.*)$
/index.php$2&key=$1
it stops working.

i figured out that if i remove ? from $show=files and change the rule
to redirect to /index.php?$2, then i can use &key=$1. but i want to
figure out how to redirect the ?show=files request AND at the end add
&key=$1


RewriteRule does not match against the query string in mod_rewrite. To
match against that you will need to use

RewriteCond %{QUERY_STRING} pattern

RewriteRule works against the REQUEST_URI..

Therefore, as per your examples above:

RewriteRule ^test/(.+)/(.*)$ /index.php$2&key=$1

Consider this URI:
/test/dir1/dir2/?var=val

The result would be:
/index.phpdir2/&dir1

If you want to keep the original query string with your request, add the
[QSA] flag at the end of the RewriteRule statement (Query String Append)..

Using this with the same URI above...
RewriteRule ^test/([^/]+)/([^/]+)$ index.php?$2&key=$1 [QSA]

/index.php?dir2&key=dir1&var=val

HTH

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Feb 2 '06 #3
Justin,

Thank you for your elaborate answer. Perhaps im not doing something
right, but here is what I get:

[Thu Feb 02 11:08:15 2006] [error] [client 127.0.0.1] File does not
exist: D:/system_programs/xampp/htdocs/gallery

This is in response to my request:

http://localhost/gallery/galleryname...how_per_page=5

That sould be processed with this rule:

RewriteRule ^gallery/([^/]+)/([^/]+)$ /index.php?$2&gallery_name=$1
[QSA]

:) why?

P.S. Tried on my Apache server on a linux box - same result.

Feb 2 '06 #4
na************@msn.com wrote:
Justin,

Thank you for your elaborate answer. Perhaps im not doing something
right, but here is what I get:

[Thu Feb 02 11:08:15 2006] [error] [client 127.0.0.1] File does not
exist: D:/system_programs/xampp/htdocs/gallery

This is in response to my request:

http://localhost/gallery/galleryname...how_per_page=5

That sould be processed with this rule:

RewriteRule ^gallery/([^/]+)/([^/]+)$ /index.php?$2&gallery_name=$1
[QSA]

:) why?


^gallery/([^/]+)/([^/]+)$
match REQUEST_URI that:
* starts with literal "gallery/"
* followed by one or more characters that are not "/"
* followed by a "/"
* ends with one or more characters that are not "/"

Your request:
gallery/galleryname/
* starts with literal "gallery/"
* followed by one or more characters that are not "/"
* followed by a "/"
* DOES NOT end with one or more characters that are not "/"

You can modify the rule to accept this, or create a second rule, I opt
for modification:

RewriteRule ^gallery/([^/]+)(/([^/]+))?$ /index.php?$3&gallery_name=$1 [QSA]

HTH

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Feb 2 '06 #5
still doesn't work :(

after playing around, i found this to work:

RewriteRule ^gallery/([^/]+)/(.*)$ /index.php?gallery_name=$1$2 [QSA]

However, if my query string is
"mAIJX1CKDGM6nDKq/QUfPXMxIKOrTdZQrPcxAdM/DeJKhH9cycqCJrjZsKgOePSF"
(that is, it contains "/"), then it's not interpreted properly. and i
believe it's my regex syntax in mode_rewrite.

This is simply a headache :) I spent so many hours on this one rule.
ouch. any ideas?

Thanks!

Feb 2 '06 #6
RewriteRule ^gallery/([^/]+)/$

worked.

Feb 4 '06 #7

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...
1
by: Shabam | last post by:
In Apache there's a pretty powerful module called mod_rewrite. Is there anything like that in dot net?
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...
4
by: Hermann.Richter | last post by:
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 ...
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...
2
by: Susanne West | last post by:
hi group. i'm tackling a bigger project that will use mod_rewrite to patch a series of urls into a master php-script. this script builds the page framework that contains a series of elements...
3
by: Dr. No | last post by:
I am new to using mod_rewrite and am trying to rewrite a URL to pass values to my script so that: http://www.myclient.com/everything/animals/mammals/cats is transformed into ...
1
by: jaimebienlesfruits | last post by:
Hi, I'm currently using mod_rewrite to rewrite URLs with server variables. RewriteEngine on RewriteRule ^(+)$ /layout4/$1/ RewriteRule ^(+)/?$ index.php?dir=&page=$1 RewriteRule...
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.