Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:

Password:

Remember me

mod_rewrite Rule
Welcome, Guest. Please login or register.
December 02, 2008, 04:41:14 AM
11304 Posts in 1248 Topics by 498 Members
Latest Member: katCheeme
Experts Round Table Network  |  Webservers  |  Apache  |  mod_rewrite Rule « previous next »
Pages: [1]
Author Topic: mod_rewrite Rule  (Read 798 times)
CrYpTiC_MauleR
Site Builder

Offline Offline

Posts: 489



WWW
« on: May 18, 2006, 05:16:10 PM »

I have the following...

RewriteRule ^/([a-z]+)/$ $1.html

So if someone accesses /test/ it will actually show /test.html

Works great, but I want to prevent someone accessing /test.html by typing in /test.html

If someone does that I want it to 404 instead, how would I go about doing that? Allowing only /test/ and not /test.html

I've tried but doesnt work because the rewrite rules redirects itself and accessed /test.html so prevents itself from accessing it. =o(
Logged

[x] Fight | www.crypticmauler.com
"You must be
rdivilbiss
Governing Council Member
*
Offline Offline

Posts: 414



WWW
« Reply #1 on: May 18, 2006, 07:46:03 PM »

I don't know the answer (circular reference comes to mind, however.)

However, your avatar has the wrong close...

Isn't it

Code:

<?PHP

?>


Logged

Rod
CrYpTiC_MauleR
Site Builder

Offline Offline

Posts: 489



WWW
« Reply #2 on: May 18, 2006, 08:26:18 PM »

Hey I picked what was already available =oP, I wish I could have my own but as far as I remember I'm not allowed to since I'm not a Mentor.'

You have any ideas on what to do about the rule? Would maybe blocking direct access to .html files by IP except localhost work? Havent tried that, but might e promising. I think I read somewhere that mod_rewrite rules can be done to skip rest of rules if condition is met, that could stop this loop, but have no idea how its done.
Logged

[x] Fight | www.crypticmauler.com
"You must be
rdivilbiss
Governing Council Member
*
Offline Offline

Posts: 414



WWW
« Reply #3 on: May 18, 2006, 09:02:19 PM »

Quote from: "CrYpTiC_MauleR"
You have any ideas on what to do about the rule?


Sorry, but I can not help more about the rule.
Logged

Rod
GrandSchtroumpf
Mentor

Offline Offline

Posts: 410



« Reply #4 on: May 19, 2006, 01:31:54 AM »

Try something like this:

RewriteRule ^/([a-z]+)/$ $1.html [L]
RewriteRule ^/[a-z]+\.html/$ error404.html [L]

(the [L] stands for LAST)
Logged
VGR
Mentor

Offline Offline

Posts: 682



WWW
« Reply #5 on: May 19, 2006, 01:35:27 AM »

won't you use a rewritecond -f (file does not exist) to map the 404 to ?
Logged

techie overlord, answers all kind of questions on http://www.europeanexperts.org
CrYpTiC_MauleR
Site Builder

Offline Offline

Posts: 489



WWW
« Reply #6 on: May 19, 2006, 02:43:17 PM »

didnt work, it still allowed me to type in test.html =o(
Logged

[x] Fight | www.crypticmauler.com
"You must be
GrandSchtroumpf
Mentor

Offline Offline

Posts: 410



« Reply #7 on: May 19, 2006, 04:16:00 PM »

I'm not that familiar with mod rewrite.  I just redirect all pages to a php file and process my url in php.
I think the [L] just tells the engine to processing the code.
But it seems like once your url has been rewritten all the rules are processed again from the beginning with the new url value.  It does make sense.

The only solution i found is to place your .html files in a subdirectory:
  RewriteRule ^/([a-z]+)/$ /html/$1.html

I guess your main problem with allowing access to the test.html file is that relative urls will be broken since it's one level above the test dir...
If you place your .html files in a subdir, then you are at the same level... and then you can use .htaccess to simply deny all access to that dir.
Logged
CrYpTiC_MauleR
Site Builder

Offline Offline

Posts: 489



WWW
« Reply #8 on: May 19, 2006, 05:22:21 PM »

now why didnt I think of that? I will just put all the files into a directory and protect that directory, thanks!
Logged

[x] Fight | www.crypticmauler.com
"You must be
CrYpTiC_MauleR
Site Builder

Offline Offline

Posts: 489



WWW
« Reply #9 on: May 19, 2006, 05:40:38 PM »

Ok came across a problem:


<Directory "SERVER_PATH/public_html">
RewriteEngine on
RewriteBase /
RewriteRule ^([a-z]+)/$ html/$1.html
</Directory>

<Directory "SERVER_PATH/public_html/html">
Order deny,allow
Deny from all
</Directory>

When above is used I get a 403 when I try to view site, reason being is when I access /test/ its being directed to /html/test.html which is protected. Page cant be viewed unless protection is not put, but need that directory protected, how would I go about doing this? Thanks!
Logged

[x] Fight | www.crypticmauler.com
"You must be
GrandSchtroumpf
Mentor

Offline Offline

Posts: 410



« Reply #10 on: May 19, 2006, 06:07:07 PM »

lol, i guess that's why i use php...
BTW, why do you need protection?
Logged
GrandSchtroumpf
Mentor

Offline Offline

Posts: 410



« Reply #11 on: May 20, 2006, 07:34:23 AM »

read this thread if you want do the redirection using php:
http://www.expertsrt.net/forum/viewtopic.php?t=514
Logged
Pages: [1]
« previous next »
    Jump to: