Jump to content

[SOLVED] When path starts with admin go there


jordanwb

Recommended Posts

Currently I have the following .htaccess file:

 

RewriteEngine On

RewriteBase /~jordanwb/jscm

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^.*$ index.php

 

Which works, but I want Admin related features to be directed to admin.php, I modified it like so:

 

RewriteEngine On

RewriteBase /~jordanwb/jscm

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^admin(.*) admin.php
RewriteRule ^.*$ index.php

 

but I still get sent to index.php but with broken CSS and images. All the links start with /~jordanwb/jscm which is a real path, then a fake path like /pages/hello (/~jordanwb/jscm/pages/hello), for admin it would be similar: /~jordanwb/jscm/admin/pages

Link to comment
Share on other sites

Do you mean something like this...

 

RewriteEngine On  
   
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^admin/?(.+) admin.php?page=$1

 

Which will take a URL from the user such as http://www.example.com/admin/manage-users and will send back http://www.example.com/admin.php?page=manage-users. (I believe :))

Link to comment
Share on other sites

Did you try my code? By the sounds of it you could remove the ?page=$1 and it will do exactly what you want it to, I was simply passing the remainder of the URL as a $_GET variable, you could of course use $_SERVER['REQUESTED_URI'] if you needed to know what page the user requested.

Link to comment
Share on other sites

If like this:

 

Options +FollowSymlinks
RewriteEngine On

RewriteBase /~jordanwb/jscm

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^admin/?(.+) admin.php [L]
RewriteRule ^.*$ index.php

 

the css still breaks.

Link to comment
Share on other sites

The paths to the style sheets are absolute:

 

<link rel="stylesheet" href="/~jordanwb/jscm/themes/WebDevTheme/style.css" type="text/css" media="screen" />

 

Pointing the browser to http://99.224.34.94/~jordanwb/jscm/themes/WebDevTheme/style.css does not give the stylesheet but rather /~jordanwb/jscm/index.php. Commenting out the "RewriteRule ^admin/?(.+) admin.php [L]" line fixes this but does not fix my other problem.

Link to comment
Share on other sites

Ahhh, I forgot that RewriteConds only apply to the closest rewrite rule.

 

 

RewriteCond %{SCRIPT_FILENAME} !-d

RewriteCond %{SCRIPT_FILENAME} !-f

 

Rule1

 

RewriteCond %{SCRIPT_FILENAME} !-d

RewriteCond %{SCRIPT_FILENAME} !-f

 

Rule2

 

 

I'm sure there's a way to do it less redundantly, but I don't remember how off the top of my head.

Link to comment
Share on other sites

Okay so the css works now, but http://99.224.34.94/~jordanwb/jscm/admin still does not go to /~jordanwb/jscm/admin.php

 

.htaccess

 

Options +FollowSymlinks
RewriteEngine On

RewriteBase /~jordanwb/jscm

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^admin/?(.+)$ admin.php [L]

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^.*$ index.php

Link to comment
Share on other sites

RewriteRule ^admin/?(.+)$ admin.php [L]

 

 

I should've seen that earlier...

 

 

While /? means that the trailing / is optional, .+ means that 1 of any character is required.  (You'll notice that if you go to admin/ it will probably work.)

 

 

Anyway, I would try:

 

RewriteRule ^admin admin.php [L]

 

 

(Unless you want to capture what comes after admin it doesn't matter.)

 

 

If that doesn't suit your needs:

 

 

RewriteRule ^admin/?(.*)$ admin.php [L]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.