Forum Moderators: phranque

Message Too Old, No Replies

url re write problem

can any one plz see my code and help me out.

         

itsmani1

12:56 pm on Jun 2, 2005 (gmt 0)



Here is my code....
is there any error in it? problem to me is when i type http://example.com/test/catid/53 in the address bar i want it to go to: http://example.com/test/index.php?catid=53
but does not do tht. and says The Page Cannot Be Found.

RewriteEngine on
RewriteRule ^/catid/([0-9]+)$ /test/index.php?catid=$1 [R]
ReWriteRule ^/pag/([a-z]+)$ /test/index.php?pag=$1 [R]
ReWriteRule ^/pag/css/([a-z]+.[a-z]+)$ /test/css/$1 [R]
ReWriteRule ^/pag/images/([a-z]+_[0-9]+.jpg)$ /test/images/$1 [R]
ReWriteRule ^/catid/uploads/([a-z]+.jpg)$ /test/uploads/$1 [R]
ReWriteRule ^/catid/css/([a-z]+.[a-z]+)$ /test/css/$1 [R]
ReWriteRule ^/catid/images/([a-z]+_[0-9]+.jpg)$ /test/images/$1 [R]
ReWriteRule ^/catid/uploads/([a-z]+.jpg)$ /test/uploads/$1 [R]
RewriteRule ^/subcat/([0-9]+)$ /test/index.php?catid=$1 [R]
ReWriteRule ^/subcat/css/([a-z]+.[a-z]+)$ /test/css/$1 [R]
ReWriteRule ^/subcat/images/([a-z]+_[0-9]+.jpg)$ /test/images/$1 [R]
ReWriteRule ^/subcat/uploads/([a-z]+.jpg)$ /test/uploads/$1 [R]

######################################################################

[edited by: jdMorgan at 4:46 pm (utc) on June 2, 2005]
[edit reason] No URLs, please. See TOS. [/edit]

jdMorgan

4:48 pm on Jun 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is this code for httpd.conf, or for .htaccess?
Are you sure that the FollowSymLinks or SymLinksIfOwnerMatch Option is set?
Do you really want a redirect, or do you want an internal rewrite?

Jim

itsmani1

12:57 pm on Jun 4, 2005 (gmt 0)



this is .htaccess file code...
and i wants liks to rewrite...

itsmani1

1:02 pm on Jun 4, 2005 (gmt 0)



lets take a simple example
http://206.***.164.234/send-gifts-to-pakistancom/test.php

see this link here i have some links like

http://206.***.164.234/send-gifts-to-pakistancom/log/1.html
http://206.***.164.234/send-gifts-to-pakistancom/log/2.html

now what i want is to redirect these links to :::
http://206.***.164.234/send-gifts-to-pakistancom/test.php?log=1
and
http://206.***.164.234/send-gifts-to-pakistancom/test.php?log=2

here is my .htaccess file code....

--------------------
Options +FollowSymlinks
rewriteengine on
RewriteRule ^/log/([0-9]).html$ http://206.***.164.234/send-gifts-to-pakistancom/test.php?log=$1 [R]
-------------------
and it does not works. can u plz. help me out?
Thanks in advance...

[edited by: jdMorgan at 1:59 am (utc) on June 7, 2005]
[edit reason] De-linked. [/edit]

jd01

2:24 am on Jun 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi itsmani1,

Options +FollowSymlinks
rewriteengine on
RewriteRule ^/log/([0-9]).html$

This does not work, because the above rule is looking for a / to start the file, but Apache strips the preceding / in the htaccess file.

RewriteRule ^log/([0-9]+)\.html$

The + is added in case you have more than one number EG 11, \. rather than .(dot) makes sure only a true .(dot) character is matched, rather than 'any character except a line break'. It is also wise to add a L 'last' flag to your directives [R,L], unless you know you do not need it. Finally, the R defaults to a 302 temporary redirect, so it is normally better to add R=301, for a permanent move.

Your full rule would end up looking something like this: (assuming it is in the correct directory to 'catch' the request for the file)

RewriteRule ^log/([0-9]+)\.html$ http://yoursite.com/send-gifts-to-pakistancom/test.php?log=$1 [R=301,L]

Hope this helps.

Justin

editordude

11:40 am on Jun 5, 2005 (gmt 0)

10+ Year Member



^ Nice solution.
Would you mind explaining why you would use the 'last' flag. [L]

I'm guessing it's telling Apache to stop reading further rules if it matches which makes sense but then if it does match you are directed so it wouldn't read further?

jdMorgan

4:49 pm on Jun 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> but then if it does match you are directed...

No. Without the [L] flag, all redirections are deferred until all rules have been processed. In the case of internal rewrites, invokation of the content-handler is similarly deferred. Always use [L] unless you have a specific reason not to -- i.e. always use it unless you really do want to process the output from the current rule through one or more subsequent rules.

There are occasions when you want to do a multi-step rewrite using several rules in sequence, and in those cases, then omitting [L] is correct. But these cases are relatively rare in simple Web site configurations.

Jim

itsmani1

7:04 am on Jun 7, 2005 (gmt 0)



Now as i have changed my .htaccess file and new looks like this:

RewriteEngine on
RewriteRule ^log/([0-9]+)\.html$ http://206.***.164.234/send-gifts-to-pakistancom/test.php?log=$1 [R=301,L]

so when i type
http://206.***.164.234/send-gifts-to-pakistancom/log/1.html
in my browser it should send me to http://206.***.164.234/send-gifts-to-pakistancom/test.php?log=1 but it does not work. you can chek the above link man. let me add one thing tht both .htaccess file and test.php are in same directory.

mani

[edited by: jdMorgan at 7:10 am (utc) on June 7, 2005]
[edit reason] No URLs, no IP addresses, please. [/edit]

jd01

8:19 am on Jun 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What exactly do you mean by does not work?

Does the redirect start?
Do you get a server error?
Do you get a 404 error?

What directory is your .htaccess file in?
If the .htaccess is in: (the main directory)
206.***.164.234/

You will need to move it to: send-gifts-to-pakistancom/
or add send-gifts-to-pakistancom/ to your rule.

RewriteRule ^send-gifts-to-pakistancom/log/([0-9]+)\.html$ [206.***.164.234...] [R=301,L]

If it is in log/ you will need to remove the log/
RewriteRule ^([0-9]+)\.html$ [206.***.164.234...] [R=301,L]

If none of these solve the problem, please post exactly what does not work, and any errors from your server logs.

Justin

itsmani1

11:22 am on Jun 7, 2005 (gmt 0)



Does the redirect start? => No
Do you get a server error? => Page not found.
Do you get a 404 error? => No
-------------------------------------------------
.htaccess file is at root.

This is the .htaccess file code.

RewriteEngine on
RewriteRule ^log/([0-9]+)\.html$ [206.169.164.234...] [R=301,L]

and test.php is also at root.
wot else
but in result my rewrite does not work.

itsmani1

12:31 pm on Jun 7, 2005 (gmt 0)



when i type :
[206.169.164.234...]
in ma browser it just send me to:
[206.169.164.234...]
--------------
just tell me the rewrite rule:
----------
my .htaccess file , my test.php are in same dir.
--------------------------
Muhammad Abdul Mannan
Islamabad, Pakistan

itsmani1

6:38 am on Jun 7, 2005 (gmt 0)



this is my very simple .htaccess file:

RewriteEngine on
RewriteRule ^old.html$ new.html [R]
-----------------------------------
and i am testing it on the following links but it does not works, my .htaccess file is present in test foler and my new.html and old.html both are also in test folder.

http://example.com/test/new.html
http://example.com/test/old.html

any help plz..........

[edited by: jdMorgan at 6:11 pm (utc) on Aug. 18, 2005]
[edit reason] Removed URLs per TOS. [/edit]

varunkrish

9:02 am on Jun 7, 2005 (gmt 0)

10+ Year Member



please note ..rewrites only work if the actual files are not present...

Mod rewrite is used mainly for this i suppose

if u have a old.html stored in your server..

then a request to old.html will go to the file and not to the new.html

thats what i think... corect me if i am wrong

jd01

9:04 am on Jun 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi itsmani1,

I am not sure what you mean by doesn't work, but I would recommend trying this:

RewriteRule ^old.html$ /test/new.html [R]

In the .htaccess file the full path to the directory should be used, because the request is 'sent back' to the server root as a new request after the redirection happens.

If this does not correct the issue, please post exactly what you mean by does not work... Server error? 404 error? No rewrite?

Hope this helps.

Justin

** Rewrites work regardless of whether the files are present/exist or not.

[edited by: jd01 at 9:05 am (utc) on June 7, 2005]

varunkrish

9:04 am on Jun 7, 2005 (gmt 0)

10+ Year Member



just try using this instead

in ur htaccess

redirect permanent /old.html www.site.com/new.html

itsmani1

11:07 am on Jun 7, 2005 (gmt 0)



this is my .htaccess present in test dir.

RewriteEngine on
RewriteRule ^old.html$ /test/new.html [R]

i want my server to send :
http://www.example.com/test1/old.html

to

http://www.example.com/test1/new.html

what happens as a result of this is => it does not redirects. it gives me tht page does not found. this is the whole problem. bottom line is redirect is not working ...

[edited by: jdMorgan at 1:22 am (utc) on June 8, 2005]
[edit reason] No URLS. Please see Terms of Service. [/edit]

jdMorgan

1:28 am on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here are two simple rules. Try each one by itself. Request old.html from your server, and you should see the contents of /test/new.html.

The first rule does an external redirect, and your browser address bar should change to show /test/new.html. The second rule does an internal rewrite, and is "silent."


Options +FollowSymLinks
RewriteEngine on
RewriteRule ^old.html$ http://www.example.com/test/new.html [R=301,L]

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^old.html$ /test/new.html [L]

If neither of these work, then contact your host, as it is likely that you have a server configuration problem that is preventing mod_rewrite code from working.

Jim

itsmani1

8:33 am on Jun 8, 2005 (gmt 0)



i have a question man....
if some one is using apache 1.3 on windows machine will mod_rewrite work there or not? because some days ago i tested mode_rewrite on a linux machine having red hat distributation with apache 2.0 and it worked fine (worked fine means rewriting did the trick) and now i am testing mod_rewrite on a windows machine with apache 1.3 and its not working. any comments...

jd01

10:06 pm on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem may be your server, but this:

RewriteEngine on
RewriteRule ^old.html$ /test/new.html [R,L]

Will not work for this:
i want my server to send :
http://www.example.com/test1/old.html

to

http://www.example.com/test1/new.html

Unfortunately, rewrites have to be exact, the rule you are using redirects to the /test/ directory, but your example states test1.

You would need to use this for test1:
RewriteRule ^old.html$ /test1/new.html [R,L]

Added: Flags to rules. Oops!

Justin

itsmani1

7:33 am on Jun 9, 2005 (gmt 0)



i have the following 3 files in my rewrite-testfolder directory

shortandsweet1.html
frustrating.php
.htaccess

here is my .htaccess file code.

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^shortandsweet.html /frustrating.php

now when i type ==>> [localhost...]
in my browser instead of redirecting me to [localhost...] it shows the page with message

Not Found
The requested URL /rewrite-testfolder/shortandsweet.html was not found on this server.

--------------------------------------------------------------------------------

Apache/1.3.23 Server at localhost Port 80

-----------------
any solution pzl..........

jdMorgan

3:43 pm on Jun 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In /rewrite-testfolder/.htaccess:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^shortandsweet\.html$ [b]/rewrite-testfolder[/b]/frustrating.php [L]

Jim

itsmani1

5:41 am on Jun 10, 2005 (gmt 0)



and the result of
[localhost...]
is
The page cannot be found
The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.

--------------------------------------------------------------------------------

Please try the following:

If you typed the page address in the Address bar, make sure that it is spelled correctly.

Open the localhost home page, and then look for links to the information you want.
Click the Back button to try another link.
Click Search to look for information on the Internet.

HTTP 404 - File not found
Internet Explorer

jdMorgan

3:53 pm on Jun 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please post your error log.

Jim

itsmani1

7:33 am on Jun 11, 2005 (gmt 0)



sorry man i am disturbing u again and again. hope you won't mind. can u tell me what do u mean by log? u said about log in ur last post.

-------------------
Muhammad Abdul Mannan
Islamabad, Pakistan

itsmani1

10:40 am on Jun 11, 2005 (gmt 0)



hi there...
one more question?
is there any way to check weather mod_rewrite is enabled or not?

Thanks.

Muhammad Abdul Mannan
Islamabad, Pakistan

Dapuzz

11:01 am on Jun 11, 2005 (gmt 0)

10+ Year Member



<? phpinfo();?>
Look into Apache section:
Loaded modiule -> [...]mod_auth, mod_access, mod_rewrite, mod_alias [...]