jordanwb Posted October 7, 2009 Share Posted October 7, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/176866-solved-when-path-starts-with-admin-go-there/ Share on other sites More sharing options...
cags Posted October 7, 2009 Share Posted October 7, 2009 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 ) Quote Link to comment https://forums.phpfreaks.com/topic/176866-solved-when-path-starts-with-admin-go-there/#findComment-932643 Share on other sites More sharing options...
jordanwb Posted October 7, 2009 Author Share Posted October 7, 2009 Let's say I have this url: http://example.com/pages/hello pages/hello gets sent to index.php because it doesn't start with admin http://example.com/admin/pages/hello pages/hello gets sent to admin.php because it starts with admin. Quote Link to comment https://forums.phpfreaks.com/topic/176866-solved-when-path-starts-with-admin-go-there/#findComment-932646 Share on other sites More sharing options...
cags Posted October 7, 2009 Share Posted October 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/176866-solved-when-path-starts-with-admin-go-there/#findComment-932647 Share on other sites More sharing options...
jordanwb Posted October 7, 2009 Author Share Posted October 7, 2009 I tried your code and my css breaks: http://99.224.34.94/~jordanwb/jscm/admin I can fix that "undefined index" notice later. Quote Link to comment https://forums.phpfreaks.com/topic/176866-solved-when-path-starts-with-admin-go-there/#findComment-932673 Share on other sites More sharing options...
corbin Posted October 7, 2009 Share Posted October 7, 2009 You'll need to put [L] after the rule since RewriteRule ^.*$ index.php Will also match things starting with admin. Quote Link to comment https://forums.phpfreaks.com/topic/176866-solved-when-path-starts-with-admin-go-there/#findComment-932675 Share on other sites More sharing options...
jordanwb Posted October 7, 2009 Author Share Posted October 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/176866-solved-when-path-starts-with-admin-go-there/#findComment-932679 Share on other sites More sharing options...
corbin Posted October 7, 2009 Share Posted October 7, 2009 Use absolute paths then. Your HTML is probably like: href="css/something.css" That will do /admin/css/something.css instead of /css/something.css. Quote Link to comment https://forums.phpfreaks.com/topic/176866-solved-when-path-starts-with-admin-go-there/#findComment-932695 Share on other sites More sharing options...
jordanwb Posted October 8, 2009 Author Share Posted October 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/176866-solved-when-path-starts-with-admin-go-there/#findComment-932770 Share on other sites More sharing options...
corbin Posted October 8, 2009 Share Posted October 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/176866-solved-when-path-starts-with-admin-go-there/#findComment-932771 Share on other sites More sharing options...
jordanwb Posted October 8, 2009 Author Share Posted October 8, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/176866-solved-when-path-starts-with-admin-go-there/#findComment-932772 Share on other sites More sharing options...
corbin Posted October 8, 2009 Share Posted October 8, 2009 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] Quote Link to comment https://forums.phpfreaks.com/topic/176866-solved-when-path-starts-with-admin-go-there/#findComment-932792 Share on other sites More sharing options...
jordanwb Posted October 8, 2009 Author Share Posted October 8, 2009 RewriteRule ^admin/?(.*)$ admin.php [L] works. Thanks corbin and cags. Quote Link to comment https://forums.phpfreaks.com/topic/176866-solved-when-path-starts-with-admin-go-there/#findComment-932976 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.