problem with mod_rewrite

Started on the old forum in July 2011 · view the original in the archive · old links redirect here

#apache #htaccess #modrewrite #profile

8 replies · 592 views · started 15 years ago · 1 min read

4 participants
djdevil89 Senior · 287 posts #1

Hey guys,

as stated in one of my posts/threads before i am working on a wap/web community and im getting quite forward with it, my problem now is i use mod_rewrite to make the url friendly

for example i have this

Options +FollowSymlinks
RewriteEngine on
DirectorySlash on
ErrorDocument 404 http://domain.com/wap/error.php
RewriteRule ^users/([0-9]+)-([a-z]+) users.php?id=$1 [NC]

this makes profiles available like http://domain.com/wap/users/?id=1 now the problem is if i open the profile like http://domain.com/wap/users?id=1 my theme messes up incase it wont load at all because the path is messed, now i am looking for a way to force the leading / with mod_rewrite or if needed even with php is there any way to do that?

foreach ($_SERVER as $server => $value)
{
echo "$server is $value<br />";
}
djdevil89 Senior · 287 posts #3

Thats what i am doing right now but its not the best way to do i am looking for an alternative way

Added after 21 minutes:

okay i came up with this

RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301] 

but this puts a trailing slash to the .css aswell and therefore makes it unusable

foreach ($_SERVER as $server => $value)
{
echo "$server is $value<br />";
}
CreativityKills Lead · 833 posts #4

DjMatrix wrote: Thats what i am doing right now but its not the best way to do i am looking for an alternative way

theres nothing like the "best way", whether its the absolute url path to d style sheet, or just the relative path, it still sends a new independent request for d the css externally

morse Senior · 364 posts #5

you are using a re-director and that is what is giving you error. You will have to edit all prevalent links in the script.

tinyurl.com/earnbymobile Easy earning for Indians

Alternative mobile advertising network .. Minimum 100 USD pay / NET15 pay cycle, Good Brand, Best targeting for Android goo.gl/6vub3

djdevil89 Senior · 287 posts #7

morse wrote: you are using a re-director and that is what is giving you error. You will have to edit all prevalent links in the script.

thanks fpr pointing that out so what you think the htaccess code should be like?

foreach ($_SERVER as $server => $value)
{
echo "$server is $value<br />";
}
morse Senior · 364 posts #8

DjMatrix wrote: thanks fpr pointing that out so what you think the htaccess code should be like?

R=301 is a redirector , right ?? remove it 🙂 problem solved . But then you have to manually edit each and every link in the web page to its absoluteness for you to have links pointed to right pages.

tinyurl.com/earnbymobile Easy earning for Indians

Alternative mobile advertising network .. Minimum 100 USD pay / NET15 pay cycle, Good Brand, Best targeting for Android goo.gl/6vub3

djdevil89 Senior · 287 posts #9

okay i have it thanks a lot i didnt remove the redirect but went and removed the trailing slash on images and css using preg_replace

foreach ($_SERVER as $server => $value)
{
echo "$server is $value<br />";
}

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close