Jump to content

Recommended Posts

ive rewritten my urls so that:

 

site.com/section/index.php?subsection=X&article=Y

becomes

site.com/section/subsection/article.html

 

but now it seems to think that subsection is an actual folder and has thrown out all my '../filename' links. So it doesn't find the CSS or images anymore. i was using ../ so that it looked one folder below for the files, it now thinks the files are 2 folders below (because of the rewrite)

 

Does anyone know how to solve this? i can just put the root address in because i'm using a staging server for now and don't want to have to go round changing all the URLs before launch

 

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/107983-url-rewriting/
Share on other sites

RewriteEngine On
RewriteRule ^([^/]*)/$ /section/index.php?category=$1 [L]
RewriteRule ^([^/]*)/([^/]*)-([^/]*)\.html$ /section/index.php?category=$1&url=$2&id=$3 [L]

 

the rewrite works fine. problem is it causes the folder to be seen as one deeper than it physically is, so ../doesn't work anymore. Also, using ../../ instead would mean that the article level wouldn't work even if category level was finding the files

Link to comment
https://forums.phpfreaks.com/topic/107983-url-rewriting/#findComment-553490
Share on other sites

what does the extra /. mean?

 

 

the rewrite works perfectly, my problem is that it creates 'virtual folders' and this extra folder deptch means the way i reference image/php file includes /css includes etc doesn't work properly. i use ../ which looks one depth below, but the /section/ created means ../ only looks in the same directory as the .index.php file is

 

hard to explain, do you get me?

Link to comment
https://forums.phpfreaks.com/topic/107983-url-rewriting/#findComment-553544
Share on other sites

basically ^[^//.] means don't start with / or .

so /test or ../test will not be used by the rewrite..

 

can you post some links that are NOT working anymore..

as the only things that should be affected are things that end with a / or .html, so hello/world.jpg would work fine.

Link to comment
https://forums.phpfreaks.com/topic/107983-url-rewriting/#findComment-553549
Share on other sites

This problem is called absolute path problem

 

 

Here u make two rule for same page in your. htaccess file for rewrite url  this is your main problem for not getting absolute path

 

Any way I have an idea

 

If(($_GET[‘category’]!=””)&& ($_GET[‘&url’]!==””))

{

$link=”../../”;

}

else

{

$link=”../”;

 

 

}

Put  $link like

 

<link rel="stylesheet" href = "<?=$link?>css/cascading.css" type="text/css">

 

Link to comment
https://forums.phpfreaks.com/topic/107983-url-rewriting/#findComment-554034
Share on other sites

ah good idea, that works fine thanks.

 

Although, for another section i have rewritten the URLs in pretty much the same way with:

 

RewriteEngine On
RewriteRule ^([^-]*)-([^-]*)\.html$ /section/article.php?url=$1&id=$2 [L]

 

so it should go: /section/articlename-id.html

 

This normally works fine for me, but now if i have any hyphens in the url value, it makes an error because it expects the id. So the following wont work:

/section/article-name-id.html

 

any ideas? Can you 'ignore' certain characters?

Link to comment
https://forums.phpfreaks.com/topic/107983-url-rewriting/#findComment-556301
Share on other sites

Just a suggestion:

 

For CSS and Images in case URL rewritten sites, I personally would use Absolute paths, doesnt make a difference in speed as well as doesnt make a difference from which directory you call them

 

Ignore post, if you feel it is not important. but it helps me a lot.

Link to comment
https://forums.phpfreaks.com/topic/107983-url-rewriting/#findComment-556406
Share on other sites

its matter when u make fully Dynamic site like

http://huntor.org its make only one page site each time when go subfolder then page url change like

 

http://www.huntor.org/Travel-154-1.html

Then go inner directory

 

http://www.huntor.org/Travel/Apartments-507-1.html

 

I have make only one rule in .htaccess file Each time when go sub directory number of forward sleaes  “/” increase here ur absolute path make problem  because php count it as subfolder  but u set ur path(css,images) as main folder.

 

Link to comment
https://forums.phpfreaks.com/topic/107983-url-rewriting/#findComment-557159
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.