Welcome to WebmasterWorld Guest from 54.167.40.25

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

New to this Mod_ rewrite URL stuff

     
6:19 am on Dec 12, 2002 (gmt 0)

Full Member

10+ Year Member

joined:Dec 11, 2002
posts:213
votes: 0


Hello All
i have just got registered with this forum and liked the mesages posted by you guys
i dont know anything about mod rewrite url and dont know RegEx too
is there any nice and simple tutroial regarding that?
with lots of examples?

-what I ve been asked to do right now is replace & and? of query string with /(slashes).
does .htaccess file places in the directory where script present? can we have more than one .htaccess on a single machine?

any idea?
-adnan

7:34 am on Dec 12, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


adnan,

Start with the mod_rewrite documentation [httpd.apache.org] and try this short regex tutorial [etext.lib.virginia.edu].

You can have one .htaccess file in each directory/subdirectory, although it is best to minimize them because all .htaccess files in a path will have to be processed to serve a file in that path, and .htaccess processing is somewhat inefficient compared to httpd.conf.

HTH,
Jim

7:53 am on Dec 12, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 0


what I ve been asked to do right now is replace & and? of query string with /(slashes).

mod_rewrite will turn the nice URI with slashes back to the bad one with query strings but it cannot be used to produce such URIs in the first place.

Andreas

7:35 am on Dec 22, 2002 (gmt 0)

Full Member

10+ Year Member

joined:Dec 11, 2002
posts:213
votes: 0


ActuallY i want to change this URL

[xyz.com...]
show_accessories.jsp?prod_id=460&brand_name=Nokia

to

[xyz.com...]
prod_id/460/id=jsp/show_accessories.jsp/prod_id/460/
brand_name/Nokia

any help?is it possible?
-adnan

[edited by: Marcia at 8:00 am (utc) on Dec. 22, 2002]
[edit reason] side scroll [/edit]

8:06 am on Dec 22, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member marcia is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Sept 29, 2000
posts:12095
votes: 0


Welcome to WebmasterWorld, kadnan. You might want to read through the mod_rewrite tutorial [webmasterworld.com] as well as the official documentation; it's very simple to understand.

The second sample you showed is still way too long. Take some time and give more thought before you change your file structure. You'd be better off with URLs right around 35 characters. It can make a difference in a number of different ways. For one thing, on pages linking to those, long URLs will bloat the file size, and you should keep page text and html small in size. Secondly, who would link to URLs that long? It wuuld be very difficult to do.

There's more to think about than just the technical aspects, so take your time and dig in reading a bit more. There's a search available - top of the page - so you can look up different things as you go along.

5:31 pm on Dec 22, 2002 (gmt 0)

Full Member

10+ Year Member

joined:Dec 11, 2002
posts:213
votes: 0


how do i test whether Mod rewrite is working properly or not?
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^page1\.html$ page2.html [R=301,L]

this simple example is also not workin for me on my linux box how do i test it? though i know that mod rewrite is installed,whenever i go to [localhost...] then it doesnt go to page2.html,any idea?
thanx

6:44 pm on Dec 22, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 21, 1999
posts:2141
votes: 0


The example in the Intro assumes that your pages are in the root directory of a site on a typical remotely hosted account. Assuming your local server is configured similarly to a typical hosted account, moving them to the root should correct this. They appear to be in the myphp subdir.
7:24 pm on Dec 23, 2002 (gmt 0)

Full Member

10+ Year Member

joined:Dec 11, 2002
posts:213
votes: 0


my physical directory is

/var/www/html/myphp/
so local host is
[localhost...]

and i put files in /var/www/html/myphp/,htmls and .htacess files

9:31 pm on Dec 23, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 21, 1999
posts:2141
votes: 0


You say that a request for page1.html returns page1.html so the files are indeed in the "root of your site."

Assuming your local server is configured similarly to a typical hosted account...

There are hundreds of options in the httpd.conf file that control how Apache behaves. I'm thinking your problem is in this area. If you have a hosted account somewhere, you could use it to confirm that the redirect works, then attempt to configure your local server.

<added>
I set up Apache on my Red Hat 7.1 distro, been meaning to do it and finally have a reason. :) I can't surf to [localhost...] either but I can surf to [machinename...] and, after massaging my httpd.conf file, my .htaccess file works as advertised.

By machinename, I'm referring to the computer's name for networking purposes. I'm not sure how to describe it. When logged into the root directory as root, the prompt in a terminal window displays "root@machinename /root" Another way to say it is, it's the name this machine is known by on my local network.
<added>

8:23 am on Dec 24, 2002 (gmt 0)

Full Member

10+ Year Member

joined:Dec 11, 2002
posts:213
votes: 0


even change the machine name it still showing same result that is nothing
as far as remote machine is concenred,i just have FTP access to that not Telnet so cant see conf files at all
-may i send you my httpd.conf so that you can havea look thanx
-adnan
1:01 pm on Dec 24, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 21, 1999
posts:2141
votes: 0


-may i send you my httpd.conf so that you can havea look

Of course! Use the email address in my profile. Remember, you get what you pay for! :) I'm not an expert, just someone with a little experience trying to help.

8:25 pm on Dec 24, 2002 (gmt 0)

Full Member

10+ Year Member

joined:Dec 11, 2002
posts:213
votes: 0


YAaay!
thanx a lot Dave ,atlast i executed your redirect page example on My own machine it redirected me to [localhost.localdomain...] which was wrong path,anyway atlest Rewrite is working Now

-another thing is RewriteLog "mylog.log" wasnt working too and i was gettin 505 Internal server error,i checked error_log then i found there that .htacess,RewriteLog isn`t allowed,i dont know why

-Now i wll come back soon with orignal problems
Thanx a lot,this forum is great
-adnan

8:36 pm on Dec 24, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 21, 1999
posts:2141
votes: 0


I'm glad to hear that you're making progress!

-Now i wll come back soon with orignal problems
Don't be a stranger but, please, don't go to any extra trouble to find difficult problems! ;)

You haven't posted often yet so, in case no one else has mentioned it, Welcome to WebmasterWorld! :)

11:21 am on Dec 27, 2002 (gmt 0)

Full Member

10+ Year Member

joined:Dec 11, 2002
posts:213
votes: 0


hey i am back:)

things are going pretty fine yet, belated Xmas greetings to all of you

-well 2 questions first one is

-when i add RewriteLog then apache error_log says something like
[Fri Dec 27 16:05:27 2002] [alert] [client 127.0.0.1] /var/www/html/shopcart/_admin/.htaccess: RewriteLog not allowed here

-how do i do that?

Second question is that is there anyway to write a single rule for all files
i mean i want whenever someone hits *.html files it goes to *.php files
e:g file1.html->file1.php
file5.html->file5.php
or do i need to write rules/files?
thanx

12:27 am on Dec 28, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 21, 1999
posts:2141
votes: 0


The RewriteLog directive cannot be used in an .htaccess file, it may only be used in http.conf. See "Context:" at [httpd.apache.org...]

Something like this should perform the redirect you need:


Options +FollowSymLinks
RewriteRule ^(.*)\.html $1.php [L]

The "$1" in the URL on the right adds the pattern matched on the left into the URL on the right.

5:36 am on Dec 28, 2002 (gmt 0)

Full Member

10+ Year Member

joined:Dec 11, 2002
posts:213
votes: 0


thanx Dave
i will give it a try

another question, asked by my friend
he wants the url

[domainname.com...]

to

[domainname.com...] jsp/prod_id/460/id/jsp/show_accessories.jsp/
prod_id/460/brand_name=Nokia

i:e replacing? and & with "/"

- i told em that i ve been workin on rewrite so he asked em to do so, it this url sane? can it be parsed by rewrite url?
thanx

[edited by: DaveAtIFG at 6:30 am (utc) on Dec. 28, 2002]

6:47 am on Dec 28, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 21, 1999
posts:2141
votes: 0


I'm confident that it can be done using mod-rewrite. I'm also certain that it's beyond my regex skills at this point. You posed this same question in message #4 and some of our experts may be willing to help you debug YOUR code when you have something ready. But who's it really for, you or your friend? :)

Frankly, I don't understand why you would want to do this rewrite and I agree with Marcia's comments in message #5.

7:21 am on Dec 28, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 16, 2001
posts:2006
votes: 0


As long as your URL structure is consistent, you could have a URL that is shorter using mod_rewrite: [domainname.com...]

I bet you mod_rewrite is being used for WebmasterWorld threads making them look like static HTML files when in fact they are dynamic pages.

5:47 am on Dec 30, 2002 (gmt 0)

New User

10+ Year Member

joined:Dec 5, 2002
posts:25
votes: 0


why is putting a .htaccess file with a line says:

RewriteEngine on

makes everything in that directory inaccessable?

4:09 pm on Dec 31, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 21, 1999
posts:2141
votes: 0


Hey Penguinsnob, we're not ignoring you, I promise! You're fairly new here, welcome! :)

I didn't understand your question... but after reviewing some of your other posts, I think this Intro to Redirecting URLs [webmasterworld.com] probably will be useful to you.

7:29 am on Jan 1, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Dec 11, 2002
posts:213
votes: 0


hey Dave
offcrouse i won`t go for such long urls
anyhow i managed to parse that long url
but .htacess isn`t workin fine on my friend`s host machine
site always goes down when he uses modrewrite rules in .htacess file even simple redirection rule isn`t working and site stops working.when he saved blank .htaccess file then it worked
5:22 pm on Jan 1, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 21, 1999
posts:2141
votes: 0


That sounds like a server configuration problem to me, not sure where to look though. Insure that mod_rewrite is being loaded and look at the AllowOverride directives...