Jump to content


Photo

mod_rewrite


  • Please log in to reply
7 replies to this topic

#1 talreja_sapna

talreja_sapna
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 12 October 2006 - 12:29 PM

can anyone tell me how mod_rewrite works
actually i have uncommented the line in httpd file also but it is not woking
thanks
sapna

#2 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 12 October 2006 - 12:43 PM

it might be better to explain what you're trying to achieve - simply uncommenting something generally just makes things available for you to use rather than changing things automatically.

mod_rewrite is about rewriting URL's. if you've seen wikipedia's URLS, or URL's without lists of parameters after the filename, then mod_rewrite is possibly at work.

as it's generally done on a site by site basis, the best way is to create a text file in your webroot called .htaccess (notice the fullstop before the name).

as for the rest - you need to decide what you want to achieve with the URL, get a grasp of regular expressions and go from there. Here's the main doc for it: http://httpd.apache....od_rewrite.html

assuming you've already got that far, and it's not doing anything, do you have a: RewriteEngine On in your htaccess file?

hope that helps
Cheers
Mark
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#3 talreja_sapna

talreja_sapna
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 12 October 2006 - 01:09 PM

hi
actually wht i want is as soon as user register his homepage should be created(dynamic)
example if user registers by the name john
then he can visit his home page by the following url
http://domainname/john
thanks
sapna


#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 12 October 2006 - 02:34 PM

Whats your rewrite rules. Post your rewrite rulese here.

You need to setup some rewrite rules in a htaccess file in order for http://domainname/john to work.

Fo example. You have a file called profile.php and you use a url parameter called user, which profile.php uses to grab the details of that user. Instead having to type http://domainname/pr...?user=user_here
You want to use http://domainname/user_here

In order to do that a rewrite rule needs to be setup for modRewrite to use. So your rewrite rule will be something like this:
# Tell Apache you want to use mod_rewrite
RewriteEngine On

# Setup the rewrite rul
RewriteRule ^([a-zA-z]+)$ profile.php?user=$1

You cannot just uncomment the mod_rewrite module and expect it to work just like that.

#5 talreja_sapna

talreja_sapna
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 13 October 2006 - 05:35 AM

hi
thanks
actually i am working with the mod_rewrite for the first time
so for checking whether its working or not
i had written the following in .htaccess

RewriteEngine On
RewriteRule ^/alice\.html$ bob\.html

if user try to access alice.html bob.html should be called but its not working
thanks
sapna

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 13 October 2006 - 10:10 AM

Try this instead:
RewriteRule ^alice.html$ bob.html


#7 talreja_sapna

talreja_sapna
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 13 October 2006 - 12:09 PM

hi
thanks
now wht the problem i am facing is it is working on my system but not online
can i load mod_rewrite module frm my code because it is not enabled on my domain(online)
thanks
sapna

#8 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 13 October 2006 - 01:33 PM

No. You cannot enable the mod_rewrite in a htaccess file. All Apache modules have to be enabled via the server configuration (httpd.conf) file.

Ask your host whether they can enable the mod_rewrite module. If they will not enable the module then you'll either have to find a new host, or upgrade your hosting plan to one where you can control the Apache configuration yourself (most probably  a dedicated server plan) or dont use mod_rewrite.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users