Jump to content

rewrite rule and "&" character


clearmind

Recommended Posts

Hello!

 

I'm using .htaccess for rewrite rules, everything works fine,

i want to add a new rule but it seems impossible to make it work...

this is the original link: highlights.php?heraklion&city_guide

and this is the link after the desired rewriting rule: crete-highlights/heraklion/city-guide

 

I think it must be something with the "&" character....but i can't figure out...

 

I'm completelly stuck on this...

Thanks for any help

 

 

This is my existing .htaccess file, the one i want to add the rule:

Options +FollowSymlinks
RewriteEngine On

#basic navigation
RewriteRule ^excursions/?$ excursions.php [NC,L]
RewriteRule ^crete-recommended-hotels/?$ hotels.php [NC,L]
RewriteRule ^contact/?$ contact.php [NC,L]
RewriteRule ^tour-reservation/?$ tour_reservation.php [NC,L]
RewriteRule ^crete-highlights/?$ highlights.php [NC,L]

RewriteRule ^crete-recommended-hotels/([analipsi]+)/?$   hotels.php?analipsi#hotels=$1
RewriteRule ^crete-recommended-hotels/([heraklion]+)/?$   hotels.php?heraklion=$1
RewriteRule ^crete-recommended-hotels/([stalida]+)/?$   hotels.php?stalida=$1

RewriteRule ^crete-highlights/([heraklion]+)/?$   highlights.php?heraklion=$1
RewriteRule ^crete-highlights/([chania]+)/?$   highlights.php?chania=$1
RewriteRule ^crete-highlights/([rethymnon]+)/?$   highlights.php?rethymnon=$1
RewriteRule ^crete-highlights/([lasithi]+)/?$   highlights.php?lasithi=$1

Link to comment
Share on other sites

RewriteRule will only match against the REQUEST_URI, everything after the question mark in the URL is the QUERY_STRING. If you wish to match values from the QUERY_STRING then you will need to use a RewriteCond. Given the information available for your specific example, this would result in an overall pattern something like this...

 

RewriteCond %{QUERY_STRING} heraklion&city_guide
RewriteRule highlights.php crete-highlights/heraklion/city-guide

Link to comment
Share on other sites

It doesn't work...

the rules are valid apart from that one

The page without mod_rewrite is actually(and it works): http://localhost/new/html/highlights.php?heraklion&city-guide

 

The path of the city_guide.php file in the server in that way: htdocs\new\html\highlights\heraklion\city_guide.php

Please notice:

-"city_guide.php" is in "heraklion" directory.

-"city_guide.php" is included in "heraklion.php".

-"heraklion.php" is in "highlights" directory.

-"heraklion.php" is  included in highlights.php

-"highlights.php" is in "html" directory.

 

 

RewriteRule will only match against the REQUEST_URI, everything after the question mark in the URL is the QUERY_STRING. If you wish to match values from the QUERY_STRING then you will need to use a RewriteCond. Given the information available for your specific example, this would result in an overall pattern something like this...

 

RewriteCond %{QUERY_STRING} heraklion&city_guide
RewriteRule highlights.php crete-highlights/heraklion/city-guide

 

I'm feeling completely stuck here

I would appreciate any help!

 

 

Link to comment
Share on other sites

Right, so you don't want to Rewrite highlights.php?heraklion&city-guide to crete-highlights/heraklion/city-guide, you actually want to do the reverse? Also many of the patterns you currently have probably don't do what you think they should. In order to help somebody with mod_rewrite succesfully I'll need to know...

 

1.) The address you wish in the address bar.

2.) The full URL of the file you wish to be displayed (including query_string).

3.) The actual path of the file on the server.

and possibly...

4.) What folder the .htaccess file is actually in.

Link to comment
Share on other sites

Right, so you don't want to Rewrite highlights.php?heraklion&city-guide to crete-highlights/heraklion/city-guide, you actually want to do the reverse? Also many of the patterns you currently have probably don't do what you think they should. In order to help somebody with mod_rewrite succesfully I'll need to know...

 

1.) The address you wish in the address bar.

2.) The full URL of the file you wish to be displayed (including query_string).

3.) The actual path of the file on the server.

and possibly...

4.) What folder the .htaccess file is actually in.

 

Yes i want to rewrite highlights.php?heraklion&city-guide to crete-highlights/heraklion/city-guide.

The .htaccess is in the  folder called "html". That's the website's root folder

Please keep in mind all the other rules are functioning.

 

URL structure:

http://localhost/new/html/highlights.php

http://localhost/new/html/highlights/heraklion.php

http://localhost/new/html/highlights/heraklion/city_guide.php

 

This is the file structure:

htdocs\new\html\highlights.php

htdocs\new\html\highlights\heraklion.php

htdocs\new\html\highlights\heraklion\city_guide.php

 

also i call the files like this way:

heraklion.php is included in highlights.php

city_guide.php is included in heraklion.php

 

The full URL is: http://localhost/new/html/crete-highlights?heraklion&city_guide

 

Thanks again!

Link to comment
Share on other sites

A.) I don't believe that's what you want, because that is the OPPOSITE of every single rule you have so far. You want to rewrite crete-highlights/heraklion/city-guide to highlights.php?heraklion&city-guide as I've already said. But hey I guess that's just semantics.

 

B.) I didn't say they wouldn't work, I said they don't do what you think they do, there are dozens of possible URLs that will match them not just the ones you THINK will match them. Take a random pattern as an example...

 

RewriteRule ^crete-recommended-hotels/([analipsi]+)/?$   hotels.php?analipsi#hotels=$1

 

The square brackets '[' & ']' denote a character class and the + is a quantifier that says one or more of the characters in the character class. Therefore since analipsi only contains characters within that character class it will work. So will any other combination that only uses characters inside the class. Here's a list of other random characters that would match your pattern just as readily as the ones you want to match...

 

http://domain.com/crete-recommended-hotels/anal/
http://domain.com/crete-recommended-hotels/p
http://domain.com/crete-recommended-hotels/lllllllllllllll/
http://domain.com/crete-recommended-hotels/lips

 

C.) You say that's the websites root folder, but judging by the example URLs it is not the DOCUMENT_ROOT.

 

D.) None of the provided links in your last post appear to take the 'pretty' form that you are attempting so I'm still not really any closer to working out what you are trying to do.

 

Link to comment
Share on other sites

A.) I don't believe that's what you want, because that is the OPPOSITE of every single rule you have so far. You want to rewrite crete-highlights/heraklion/city-guide to highlights.php?heraklion&city-guide as I've already said. But hey I guess that's just semantics.

 

B.) I didn't say they wouldn't work, I said they don't do what you think they do, there are dozens of possible URLs that will match them not just the ones you THINK will match them. Take a random pattern as an example...

 

RewriteRule ^crete-recommended-hotels/([analipsi]+)/?$   hotels.php?analipsi#hotels=$1

 

The square brackets '[' & ']' denote a character class and the + is a quantifier that says one or more of the characters in the character class. Therefore since analipsi only contains characters within that character class it will work. So will any other combination that only uses characters inside the class. Here's a list of other random characters that would match your pattern just as readily as the ones you want to match...

 

http://domain.com/crete-recommended-hotels/anal/
http://domain.com/crete-recommended-hotels/p
http://domain.com/crete-recommended-hotels/lllllllllllllll/
http://domain.com/crete-recommended-hotels/lips

 

C.) You say that's the websites root folder, but judging by the example URLs it is not the DOCUMENT_ROOT.

 

D.) None of the provided links in your last post appear to take the 'pretty' form that you are attempting so I'm still not really any closer to working out what you are trying to do.

 

A.) I don't believe that's what you want, because that is the OPPOSITE of every single rule you have so far. You want to rewrite crete-highlights/heraklion/city-guide to highlights.php?heraklion&city-guide as I've already said. But hey I guess that's just semantics.

 

B.) I didn't say they wouldn't work, I said they don't do what you think they do, there are dozens of possible URLs that will match them not just the ones you THINK will match them. Take a random pattern as an example...

 

RewriteRule ^crete-recommended-hotels/([analipsi]+)/?$   hotels.php?analipsi#hotels=$1

 

The square brackets '[' & ']' denote a character class and the + is a quantifier that says one or more of the characters in the character class. Therefore since analipsi only contains characters within that character class it will work. So will any other combination that only uses characters inside the class. Here's a list of other random characters that would match your pattern just as readily as the ones you want to match...

 

http://domain.com/crete-recommended-hotels/anal/
http://domain.com/crete-recommended-hotels/p
http://domain.com/crete-recommended-hotels/lllllllllllllll/
http://domain.com/crete-recommended-hotels/lips

 

C.) You say that's the websites root folder, but judging by the example URLs it is not the DOCUMENT_ROOT.

 

D.) None of the provided links in your last post appear to take the 'pretty' form that you are attempting so I'm still not really any closer to working out what you are trying to do.

 

 

Thanks for the quick reply Pete

 

I think there is a kind of misunderstanding here...i'm sorry about that

I'm not so sure my English help here, but clearly i want SEO friendly urls... that means i want to hide query-strings and the php file extension..

so that means  to hide "http://localhost/new/html/crete-highlights?heraklion&city_guide"

and instead of this i want this: "http://localhost/new/html/crete-highlights/heraklion/city_guide

 

It's blame that the website is running locally, on my computer's web server and you can't see this in action..

 

I can't understand what is all about the "document root"..

Is that true .htaccess file can be placed anywhere i want to?

Link to comment
Share on other sites

.htaccess files contain 'per-directory' settings and can go in any directory in your server. The exact directory used will depend on where the URLs are relative to and to some degree the meaning of the Regex anchors. Given the information you have no provided it would seem that you simply want...

 

RewriteRule ^crete-recommended-hotels/heraklion/city_guide/?$   crete-highlights?heraklion&city_guide

 

Link to comment
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.