开发者

help with mod_rewrite

开发者 https://www.devze.com 2023-02-06 14:15 出处:网络
alright so lately ive been messing around with mod_rewrite trying to get it work on website im working on to make the urls more appealing to non-programmers so far i have.

alright so lately ive been messing around with mod_rewrite trying to get it work on website im working on to make the urls more appealing to non-programmers so far i have.

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /newstuff
RewriteRule ^page/([0-9]+)/option/([0-9]+)?$ page.php?loc=$1&option=$2

when i go to the page page/3/option/3 none of my css files or anything loads i know its because im in a different directory now but is their anyw开发者_运维知识库ay i can get it to work without having to tweak where all my files are being loaded from?


No, you will have to stop using paths relative to the old URL. It's best if you plan for this from the start in the future: either always use paths relative to the URL of the site (/css/file.css will point to the same place no matter where you are) or use absolute URLs to the files.


It is the browser which makes requests for these files, not your server, so, as you guessed, it's looking in those directories.

It's usually safest when doing something like this, to point the URLs of your images and source files to be relative to the domain name ("/images/..." instead of of "images/...").

Alternatively, you could write more rewrite rules that redirect anything with .../images/... in it to point to your images directory, but you lose caching and a number of other useful things if you do this.

As a side-note, it's usually even better to not directly encode your image directory, but rather have some configuration file with a value like $IMAGE_DIR, and then if you ever change things, you only have to update it in one place.


Can we see the URLs of the CSS files you are linking to? I would help to see them. Here's something to get you started with:

RewriteRule ^page/[0-9]+/option/[0-9]*/([^\.]+)\.css$ /newstuff/$1.css

However, if your css is located in your document root or a folder in your document root, it would be much easier just to change all your links from css to /css or /newstuff/css.
As a good practice, always use URLs relative to your document root so you can avoid rewrite problems.


i ended up getting everything sorted it was just the paths i used for all my files css,images ect. I've never used mod rewrite before so its all kind of new. I also haven't always used relative URL's which is bad and im definitely going to stop doing that. here is the site www.imstillreallybored.com/newstuff

it's a website im doing for my high school im actually redoing a lot of the back-end php turning it into object oriented classes because alot of things i call/get such as articles would be alot easier to be called through a function and passing variables.

0

精彩评论

暂无评论...
验证码 换一张
取 消