dynamic pages with .htaccess

413 Views Asked by At

I currently have dynamic pages. For example, index.php?p=proposal opens a page from /pages/landing.php in the root of my website www/researchportal/

Currently, the page http://localhost/researchportal/proposal does seem to load by its own (just the content of proposal.php, no CSS), but not through the index.php file. Which means that the CSS is not loaded properly.

http://localhost/researchportal/index.php?p=proposal

This link loads up properly with the CSS loaded.

http://localhost/researchportal/proposal

This link doesn't contain the header and CSS which are defined in the index.php file.

My .htaccess file located in the root of my website www/researchportal/

RewriteEngine On
RewriteRule ^([A-Za-z0-9-_]+)$ index.php?p=$1

Why isnt http://localhost/researchportal/proposal loading properly?

2

There are 2 best solutions below

0
On

I think the server request for xxx.css is rerouted to index.php you should add an exeption for your css and image directory to your regex pattern. Allowing an exception for robots.txt would be usefull too.

0
On

Your current rule will send all requests to index.php. You need to add a condition to prevent requests for actual files/directories that exist e.g. css from being sent to index.php

RewriteEngine On
#Also recommend that you add a an explicit RewriteBase
RewriteBase /

#only run this rule if the request is not for an existing file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-_]+)$ index.php?p=$1