mod_rewrite help

preownedweddingdresses dot ca/?designer=Watters (one word)
preownedweddingdresses dot ca/?designer=Vera+Wang (two words)

to SEO friendly please

preownedweddingdresses dot ca/designer/Watters (one word)
preownedweddingdresses dot ca/designer/Vera-Wang (two words)

What should my .htaccess file look like?
UltraFluxAsked:
Who is Participating?
 
philkeeneConnect With a Mentor Commented:
Sorry mate I think I'm stumped... Have you tried the same code on a different server... you could download this to your PC if you don't have a free server (www.easyphp.org).
That may help with diagnosing the problem, by trying to recreate it. It would also mean you could break the code when its on the different server without worrying too much.
Not sure if that is much help, but other than that, I can't really see any reason for the behaviour.
0
 
philkeeneCommented:
How's this?...


Options +FollowSymlinks
RewriteEngine on

RewriteRule - +
RewriteRule ^designer/(.+)$ ?designer=$1
0
 
UltraFluxAuthor Commented:
nope, breaks website and shows strange pages that don't exist.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
philkeeneCommented:
k try the following then... it should get you half way...

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^designer/(.+)$ ?designer=$1
0
 
UltraFluxAuthor Commented:
Ok, I see what it is doing.

It's sending me to a URL with Watters but the wrong URL.
/canada/british-columbia/watters-brides-style-1059b/

Should be:
/?designer=Watters   ->   /designer/Watters
0
 
philkeeneCommented:
Hmm it seems there is something else going on here. What are you putting in as the URL? /designer/Watters ?
0
 
philkeeneCommented:
Also does the index page automaticallly redirect at all?
0
 
philkeeneCommented:
Is it possible for you to post the code for your index page?
If not have a look for any lines containing something like the following...
header("Location: some_url.com");
0
 
philkeeneCommented:
One final suggestion is replace the htaccess line...
RewriteRule ^designer/(.+)$ ?designer=$1
with...
 RewriteRule ^designer/(.+)$ /?designer=$1
0
 
UltraFluxAuthor Commented:
Still loads same URL.
http://preownedweddingdresses.ca/canada/british-columbia/watters-brides-style-1059b/

Index is from Wordpress, not sure it will be much help...
0
 
mattibuttCommented:
Hi
If you are hosting on share server check you have the permission to use rewrite module if its works then let us know
Thanks
0
 
UltraFluxAuthor Commented:
It works. I've used it on other domains.
0
 
philkeeneCommented:
Would it be possible to include the following PHP in your index file...
 
<!-- FILENAME: <?=$_SERVER['SCRIPT_FILENAME'];?> -->
<!-- QUERY STRING: <?=$_SERVER['QUERY_STRING'];?> -->
 
... that should mean that we can view the source to see what's happening, but won't screw up your web page in the mean time.
0
 
philkeeneCommented:
Also... could you post the full htaccess code that you have if that is possible.
0
 
UltraFluxAuthor Commented:
Note: Total Cache is Disabled until I can resolve the above problem.

Included the above in the index.php file.
# BEGIN W3 Total Cache
<IfModule mod_setenvif.c>
    SetEnvIfNoCase Accept-Encoding (gzip|deflate) APPEND_EXT=.$1
</IfModule>
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} \/$
    RewriteCond %{REQUEST_URI} !(\/wp-admin\/|\/xmlrpc.php|\/wp-(app|cron|login|register).php|wp-.*\.php|index\.php) [OR]
    RewriteCond %{REQUEST_URI} (wp-comments-popup\.php|wp-links-opml\.php|wp-locations\.php) [NC]
    RewriteCond %{REQUEST_METHOD} !=POST
    RewriteCond %{QUERY_STRING} =""
    RewriteCond %{HTTP_COOKIE} !(comment_author|wp-postpass|wordpress_\[a-f0-9\]\+|wordpress_logged_in) [NC]
    RewriteCond %{HTTP_USER_AGENT} !(bot|ia_archive|slurp|crawl|spider) [NC]
    RewriteCond /nfs/c01/h14/mnt/13403/domains/preownedweddingdresses.ca/html/wp-content/w3tc/pgcache/$1/_default_.html%{ENV:APPEND_EXT} -f
    RewriteRule (.*) wp-content/w3tc/pgcache/$1/_default_.html%{ENV:APPEND_EXT} [L]
</IfModule>
# END W3 Total Cache

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
AddHandler php5-script .php

ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/png AA2592000
ExpiresByType image/jpg AA2592000
ExpiresByType image/jpeg AA2592000

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^designer/(.+)$ /?designer=$1

Open in new window

0
 
philkeeneCommented:
Could you try moving lines 36-39 to the very top of the file. I don't see how the other rewrite rules would affect what we are trying to achieve, but it is one way to try to rule it out.
Another thing would be to temporarily back up the htaccess file, and only include lines 36-39 in the live one, for a moment just to see if it works.
Don't forget to put the current one back after testing tho.
0
 
UltraFluxAuthor Commented:
36 - 39 at top of file

http://preownedweddingdresses.ca/designer/Watters
loads to
http://preownedweddingdresses.ca/canada/british-columbia/watters-brides-style-1059b/

http://preownedweddingdresses.ca/designer/Demitrios
loads to
http://preownedweddingdresses.ca/canada/british-columbia/demitrios-ivory-size-14/

36 - 39 only [ Nothing works ]
http://preownedweddingdresses.ca/designer/Demitrios

Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /nfs/c01/h14/mnt/13403/domains/preownedweddingdresses.ca/html/wp-content/plugins/custom-field-taxonomies/main.php on line 62

0
 
philkeeneCommented:
OK, I have simulated it all on my laptop. I have a simple index.php file...
 
-------------------------
FILENAME: <?=$_SERVER['SCRIPT_FILENAME'];?><br/><br/>
QUERY STRING: <?=$_SERVER['QUERY_STRING'];?>

-------------------------
 
and I have used your .htaccess file, (with lines 30-34 commented out - I think I must be missing a module in my PHP or something because that was causing problems).
 
-------------------------
# BEGIN W3 Total Cache
<IfModule mod_setenvif.c>
    SetEnvIfNoCase Accept-Encoding (gzip|deflate) APPEND_EXT=.$1
</IfModule>
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} \/$
    RewriteCond %{REQUEST_URI} !(\/wp-admin\/|\/xmlrpc.php|\/wp-(app|cron|login|register).php|wp-.*\.php|index\.php) [OR]
    RewriteCond %{REQUEST_URI} (wp-comments-popup\.php|wp-links-opml\.php|wp-locations\.php) [NC]
    RewriteCond %{REQUEST_METHOD} !=POST
    RewriteCond %{QUERY_STRING} =""
    RewriteCond %{HTTP_COOKIE} !(comment_author|wp-postpass|wordpress_\[a-f0-9\]\+|wordpress_logged_in) [NC]
    RewriteCond %{HTTP_USER_AGENT} !(bot|ia_archive|slurp|crawl|spider) [NC]
    RewriteCond /nfs/c01/h14/mnt/13403/domains/preownedweddingdresses.ca/html/wp-content/w3tc/pgcache/$1/_default_.html%{ENV:APPEND_EXT} -f
    RewriteRule (.*) wp-content/w3tc/pgcache/$1/_default_.html%{ENV:APPEND_EXT} [L]
</IfModule>
# END W3 Total Cache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
AddHandler php5-script .php
#ExpiresActive On
#ExpiresByType image/gif A2592000
#ExpiresByType image/png AA2592000
#ExpiresByType image/jpg AA2592000
#ExpiresByType image/jpeg AA2592000
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^designer/(.+)$ ?designer=$1
-------------------------
 
It gives the correct expected results...
http://localhost/testing_the_file/designer/Watter
gives...
 
FILENAME: C:/Program Files/EasyPHP 3.0/www/testing_the_file/index.php

QUERY STRING: designer=Watter
 
Which shows the htaccess is working fine. I think we need to investigate whether something else is redirecting at any point. Does the designer folder actually exist?
0
 
philkeeneCommented:
One other thing... where did you put the htaccess file? is it in the following folder?
/home/13403/domains/preownedweddingdresses.ca/html/
 
0
 
UltraFluxAuthor Commented:
Sorry for my absence

Yes, htaccess is in the root /html/

Ok used the above code.

Still end up in the same place
http://preownedweddingdresses.ca/designer/Watters
redirects to
http://preownedweddingdresses.ca/canada/british-columbia/watters-brides-style-1059b/


Query String actually used:
http://preownedweddingdresses.ca/?designer=Watters
http://preownedweddingdresses.ca/?designer=Vera+Wang
*note the + with two words
0
 
arober11Commented:
Hi, the following, unknown file or directory, rule will be encountered before and over-ride your "designer" rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

So simply move the rule before this rule e.g

#----- cut here -----
# BEGIN W3 Total Cache
<IfModule mod_setenvif.c>
    SetEnvIfNoCase Accept-Encoding (gzip|deflate) APPEND_EXT=.$1
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} \/$
    RewriteCond %{REQUEST_URI} !(\/wp-admin\/|\/xmlrpc.php|\/wp-(app|cron|login|register).php|wp-.*\.php|index\.php) [OR]
    RewriteCond %{REQUEST_URI} (wp-comments-popup\.php|wp-links-opml\.php|wp-locations\.php) [NC]
    RewriteCond %{REQUEST_METHOD} !=POST
    RewriteCond %{QUERY_STRING} =""
    RewriteCond %{HTTP_COOKIE} !(comment_author|wp-postpass|wordpress_\[a-f0-9\]\+|wordpress_logged_in) [NC]
    RewriteCond %{HTTP_USER_AGENT} !(bot|ia_archive|slurp|crawl|spider) [NC]
    RewriteCond /nfs/c01/h14/mnt/13403/domains/preownedweddingdresses.ca/html/wp-content/w3tc/pgcache/$1/_default_.html%{ENV:APPEND_EXT} -f
    RewriteRule (.*) wp-content/w3tc/pgcache/$1/_default_.html%{ENV:APPEND_EXT} [L]

# Designer Rule
  RewriteRule ^designer/(.+)$ /?designer=$1   [L,QSA]

# Default non existent file or directory rule:
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
</IfModule>

# END WordPress
AddHandler php5-script .php

ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/png AA2592000
ExpiresByType image/jpg AA2592000
ExpiresByType image/jpeg AA2592000

Options +FollowSymlinks
#----- cut ends -----

If you also want / need to translate a '-' into a '+' sign, as part of the translation. Per you original post:

> preownedweddingdresses dot ca/?designer=Vera+Wang (two words)
>
> to SEO friendly please
>
> preownedweddingdresses dot ca/designer/Vera-Wang (two words)

Then alter the Designer rule, in it's new location to:

#----- Cut here -----
# Designer Rules
  RewriteRule ^designer/([^-]+)$          /?designer=$1         [L,QSA]
  RewriteRule ^designer/([^-]+)-([^-]+)$ /?designer=$1+$2 [L,QSA]
#----- Cut ends -----
0
 
UltraFluxAuthor Commented:
0
 
arober11Commented:
Fairly simple to explain you either have a couple more re-write rules, or a default handler that are encountered before the rules above and:
a) First of all, rewrites the URL add a trailing '/' to the end.
b) Secondly, rewrites the modified URL's as follows:

/designer/Watters/      ->  /canada/british-columbia/watters-brides-style-1059b/
/designer/Vera-Wang/ -> /canada/ontario/vera-wang-genuine-silk-size-8/

See: http://httpd.apache.org/docs/2.2/mod/mod_dir.html#directoryslash

e.g. Using Firefox and the "Live HTTP Headers" plug-in, a request for http://preownedweddingdresses.ca/designer/Watters results in:

#------------------------------------
GET /designer/Watters HTTP/1.1
Host: preownedweddingdresses.ca
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8
...

HTTP/1.1 302 Moved Temporarily
Date: Mon, 06 Sep 2010 22:52:51 GMT
Server: Apache/2.0.54
Location: http://preownedweddingdresses.ca/designer/Watters/

#------------------------------------

GET /designer/Watters/ HTTP/1.1
Host: preownedweddingdresses.ca
...

HTTP/1.1 302 Moved Temporarily
Date: Mon, 06 Sep 2010 23:04:02 GMT
Server: Apache/2.0.54
Location: http://preownedweddingdresses.ca/canada/british-columbia/watters-brides-style-1059b/

#---------------------------------


If you have access to httpd.conf have a look to see what's there for your virtualhost, as there is nothing the the code above that will cause the re-writes.
0
 
philkeeneCommented:
Does the /designer/Watters folder actually exist? and if so is there an index file or an .htaccess file in there?
0
 
UltraFluxAuthor Commented:
no physical directory
0
All Courses

From novice to tech pro — start learning today.