473,909 Members | 6,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.htaccess dilemma

107 New Member
experts, i am in a mood to create clean URLs for my site. In this regard i am trying to use .htaccess. But i am absolutely nill with it. I tried a hell lot of tutorials to learn it but it was of no use. I only know how to set the DirectoryIndex so far.

Well, i am using WAMP as my webserver in my machine and my files are not yet ready for upload. My files reside in C:\wamp\www\mys ite folder. I have an index page as index.php in my root directory. I access my index page as http://localhost/mysite/index.php. Now i have a page in the root directory as class.php requiring a dynamic parameter something like http://localhost/mysite/class.php?i=2323. Now how can i make it into something like this http://localhost/mysite/class.php/2323

Please give me a clear direction step by step.
Mar 14 '09 #1
2 1374
Markus
6,050 Recognized Expert Expert
@raamay
The question is: how would you like your URL to end up? You have to have some idea.

Anyway, the general use of this it to read the url htxp://example.com/dir1/articles/2 as htxp://example.com/dir1/index.php?categ ory=articles&id =2. Which is, I suspect, somewhat like you're after?

Anyway, I'll dive into it.

First, we turn the engine on.
Expand|Select|Wrap|Line Numbers
  1. RewriteEngine On
  2.  
If you're working in a directory other than root, it is best to set the base dir. I'm not sure if this is necessary, because I remember not having to do this a while ago when running XAMPP, but since switching to EasyPHP, I've had to use it. So, set this to the dir you are currently working in. I am assuming you have the .htaccess file in the directory you want to work with. If you are rewriting the the root directory, you'll have to make according changes to the paths.
Expand|Select|Wrap|Line Numbers
  1. RewriteEngine On
  2. # The .htaccess file is in /root/dir1/
  3. RewriteBase /dir1/
  4.  
Now we want the rule.
Expand|Select|Wrap|Line Numbers
  1. RewriteEngine On
  2. RewriteBase /dir1/
  3. RewriteRule ^([a-zA-Z_-]+)/([0-9]+)$ index.php?cat=$1&id=$2 [R]
  4.  
^ Starts the rule. The regular expression (rule) basically looks for any alpha character, underscore and hyphen (a-zA-Z_-), and also allows for more than one occurence (+). The value found is then stored in a variable for later use ($1)*. Then we check for a forward slash. After that, we look for any numeric character, allowing multiple occurences. Again, this is stored in a variable for later use ($2). $ Ends the rule.

We next specify the url it should be interpreted as, using the stored variables. After this comes the flag [R] - this forces the URL to be rewritten, meaning the the URL will change. If you want the url to remain masked, you can omit this flag.

* Variables are stored successively, 1, 2, 3 ...

This should get you started.

If you have any questions, let us know.

- Markus.
Mar 14 '09 #2
raamay
107 New Member
ok my .htaccess looks like this
# this is the initialization
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# these are the rewrite conditions
RewriteCond %{REQUEST_FILEN AME} !-f
RewriteCond %{REQUEST_FILEN AME} !-d
# and finally, the rewrite rules
RewriteRule ^([a-zA-Z0-9\-]+)/?$ class.php?page= $1 [L,QSA]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ class.php?page= $1 [L,QSA]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ class.php?page= $1 [L,QSA]
Now how should i link this page in my site so that i get the desired way. I mean in this form http://localhost/mysite/class.php/1. And another thing is that if i directly type and access the page above, the page is displayed but i get just the skeleton page with no css and other graphics working. And if i click any of the links in this page, i am directed to pages like http://localhost/mysite/class.php/anotherpage.php. Please help me out!
Mar 17 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
7703
by: yawnmoth | last post by:
i'm trying to write a php script that will password protect some random directory by creating a .htaccess file, and a password file to accompany the .htaccess file, and it isn't working... specifically, i can't enter the newly created directory with a username of test, and a password of test, which is what i am trying to do. also, i'm testing this script out on a remote server, and... after this script runs, i can't delete any of the...
8
50640
by: Joshua Beall | last post by:
Hi All, How do I disable magic quotes via .htaccess? I put the following file in my webroot, but it does not disable magic_quotes_gpc (according to phpinfo(), both the local and master value are still "on") <IfModule mod_php4.c> php_value upload_max_filesize 8M
4
2998
by: Ivo | last post by:
Greetings newsgroup, I am moving some php scripts to a new host. While getting to know the server, I ran into a strange problem. If I add a .htaccess file, or more specifically: a .htaccess with content, to a folder, requesting (html and php) files from that folder results in internal server error messages. If I upload an empty .htaccess file, all is fine. Then phpinfo() tells me I am using Apache/1.3.27.
7
7558
by: John | last post by:
Hello. I want to get this blasted .htaccess file sorted out, so I can have sessions without register_globals being on. I have looked everywhere for info on this and I mean everywhere including the php.net manual. In the manual it said to include something like the following:
0
3726
by: Stoco | last post by:
I am trying to create a generic interface that will manage various ..htaccess protected directories. In the ideal world, the .htaccess would trigger a cgi script that would take login information and store it to a file, or block access all together. For example, anytime someone logs in, the .htaccess file should direct the user name and IP address to be stored in a log file through this cgi. A cron could be scheduled to determine if the...
4
10125
by: Bill | last post by:
Does ASP have a file whose function is similar to .htaccess on Apache? I'm looking to protect subdirectory content.
0
2010
by: Jack Hambabo | last post by:
Hi, I'm searching for a php script that can find out whether the current user (I know _SERVER will give me the name for non-cgi php) has the right to view a specific file. My dream is that I just need a short php script that just asks the webserver what the rights are. That seems a reasonable wish to me. If this is however not possible than I'd like a script that can
1
4904
by: nickyeng | last post by:
I have checked this info from apache website, and i confused with it. Procteing System files it said: To run a really tight ship, you'll want to stop users from setting up .htaccess files which can override security features you've configured. Here's one way to do it. In the server configuration file, put
0
11295
by: asherwolf | last post by:
Hi, I'm trying to do something I think is pretty neat, but I've just about pulled my hair out by the behavior of my server. I'm hosting on GoDaddy, using a subdomain (www.mywebpage.com maps to /mywebpage), running Apache 1.3.33, and PHP 4.3.11. The goal is to use PHP to install an .htaccess file in a folder to forbid PHP files from being accessed from outside the server. I have a working .htaccess file in one folder, and I have been...
0
11348
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11052
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10540
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9727
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7249
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6140
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3359
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.