Forum Moderators: phranque
My directory structure is something like:
/root
index.php
faq.php
/docs
index.php
view.php
What I want to do is give out URLs like:
[mydomain.com...]
[mydomain.com...]
and have content served from:
[mydomain.com...]
[mydomain.com...]
The few attempts I tried didn't work so I doubt if I understand how to write rules. These would have to be in a .htaccess file as I don't have access to the httpd.conf file.
It seems most people do not have actual files in the directory they are modifying as I want people to still have access to:
[mydomain.com...]
[mydomain.com...]
Any ideas on where I could start looking would be appreciated. By the way, I don't want to redirect the user within the browser to the dynamic url unless i absolutely have to.
- Samantha
[httpd.apache.org...]
but i'll try explaining it my own lamens terms since I am somewhat new to this also.
[example.com...] to [example.com...]
# The lines with '#' are ignored and can be removed in your htaccess file
# Turn on the rewrite engine
RewriteEngine on
# Convert your address
RewriteRule ^fakepath/fakename/1$ /filepath/realname.php?id=1 [L]
Now to break it down,
RewriteRule - how you start a rewriterule
^$ - the path will be inside these characters '^' starts line '$' ends it
fakepath/fakename/1 - your fake path without domain name
/filename/realname.php?id=1 - the path to your file excluding domian name
[L] - Short for 'Last rule' and stops the rewriting process here
# To convert your address example
RewriteRule ^1$ /docs/view.php?id=1 [L]
# or you could use
RewriteRule ^docs/1$ /docs/view.php?id=1 [L]
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI}!-d
RewriteRule ^([^/]+)/?$ /view.php?fulltitle=$1 [R]
I was hoping it would do the following:
A web user tries going to:
[mydomain.com...]
The server checks to see if the directory "howto_modify_your_account" is a directory. If not, it should rewrite the URL as:
[mydomain.com...]
the PHP script searches the DB on the fulltitle param and returns the page. Right now I'm getting a "Internal Server Error". I left the [R] option as I thought it does a redirect and changes the URL in the browser so I can see what is happening.
Not sure why its not working.
- S
It works!
The only problem I have is that if the URL is:
[mydomain.com...]
Returns a file not found (404 error). But:
[mydomain.com...]
... does work correctly. So I think I need to figure out how to add the trailing slash and format the URL before checking it with the code you provided.
Is that the ideal way?
Thanks
-S
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^([^/]+)$ $1/
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([^/]+)/$ /view.php?fulltitle=$1 [L]
It seems that the following work:
[mydomain.com...]
[mydomain.com...]
both is processed internally as:
[mydomain.com...]
Does the Rewrite cond and rules above is the best way to do the job or is there a simpler way?
Thanks jd!
- S