Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-21-2012, 02:44 PM   PM User | #1
designer76
New Coder

 
Join Date: Aug 2009
Posts: 45
Thanks: 20
Thanked 0 Times in 0 Posts
designer76 is an unknown quantity at this point
I Need Some Help And Have A Few Questions Rewriting URLS!

Hi,

The code at the bottom of this post works perfectly except for one thing. I want to be able to either add a trailing slash or make it so that the url can work with a trailing slash and without one. So: www.mysite.com/paintings and www.mysite.com/paintings/ would both work. As it stands right now, the trailing slash does not work no matter what I do. I have tried a few rewrite scripts that I have found, but the issue is that my url ends up not working, and it will read like: mysite.com/folder/mysite/html/paintings.php. The scripts that I have tried are basically reading the entire root folder on the server instead of just the HTML folder.

My second question is is there a way that I can rewrite all of the urls on my site without having to create new code inside the .htaccess file? For example, in the code below, if I add an orange.php page inside of my acrylics folder, I am going to have to paste:

Code:
RewriteRule ^artwork/([paintings]+)/([a-z]+)/([0-9]+) paintings/acrylics/orange.php?page=$3 [L]  
RewriteRule ^artwork/([paintings]+)/([a-z]+)/([a-z]+) paintings/acrylics/orange.php?page=viewall [L]
into the .htaccess file, and so on, as I add new pages. That just seems like the wrong way to go about things, and the .htaccess file can get large fairly quickly if I have lots of pages.

Any help given is much appreciated. Thank you!

Code:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.xml -f
RewriteRule ^(.*)$ $1.xml

RewriteRule ^designs/([0-9]+) designs.php?page=$1 [L]   
RewriteRule ^designs/([a-z]+) designs.php?page=viewall [L]

RewriteRule ^paintings/([0-9]+) paintings.php?page=$1 [L]   
RewriteRule ^paintings/([a-z]+) paintings.php?page=viewall [L]

RewriteRule ^artwork/([paintings]+)/([a-z]+)/([0-9]+) paintings/acrylics/blue.php?page=$3 [L]  
RewriteRule ^artwork/([paintings]+)/([a-z]+)/([a-z]+) paintings/acrylics/blue.php?page=viewall [L]

RewriteRule ^artwork/([women]+)/([a-z]+)/([0-9]+) artwork/oils/red.php?page=$3 [L]  
RewriteRule ^artwork/([women]+)/([a-z]+)/([a-z]+) artwork/oils/red.php?page=viewall [L]
designer76 is offline   Reply With Quote
Old 07-21-2012, 02:47 PM   PM User | #2
designer76
New Coder

 
Join Date: Aug 2009
Posts: 45
Thanks: 20
Thanked 0 Times in 0 Posts
designer76 is an unknown quantity at this point
If this is any help, I found this code below that fixes most of my problems except for two issues.

1. I do not want the trailing slash to effect my search page at all, because it is causing problems.

2. I can not get it to work correctly with my paging. For example: both mysite.com/acrylics/viewall/ and mysite.com/acrylics/viewall (no trailing slash) worked with the mod_rewrite I posted above, but now it doesn't. I get an error saying that viewall.php does not exist. It seems like I may be close, but I just need some help to get this working properly. Can anyone assist?

Code:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*[^/])/$ $1.php [L]

# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
designer76 is offline   Reply With Quote
Old 08-03-2012, 11:33 PM   PM User | #3
designer76
New Coder

 
Join Date: Aug 2009
Posts: 45
Thanks: 20
Thanked 0 Times in 0 Posts
designer76 is an unknown quantity at this point
Is anyone able to help with this?
designer76 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:04 PM.


Advertisement
Log in to turn off these ads.