• Hi,
    I wonder is anyone could help me out. I have installed a copy of WordPress locally via XAMPP. I need to be able to rewrite hundreds of urls with different ID’s and redirect them to a different sun directory and add in a file extension.

    This is what I have :

    RewriteCond %{QUERY_STRING} ^type=pdf&id=(.*)$
    RewriteRule /?$ /pdf/%1.pdf [L]

    This is an example of the entry URL :

    http://localhost/wordpress/?type=pdf&id=id00264

    and this is what I need :

    http://localhost/wordpress/pdf/id00264.pdf

    I don’t understand why this doesn’t worc 🙁 Any help would be very much appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • I don’t cnow if there are any other issues, but you must escape special characters in regular expressions. Try this for your rewrite condition and see if it helps:

    RewriteCond %{QUERY_STRING} ^type\=pdf\&id\=(.*)$
    Thread Starter Serensites

    (@serensites)

    Thanc you for your reply but that doesn’t seem to help.

    I am running the site locally via XAMPP. I’ve checqued the httpd.conf file and eveything seems fine. If I clicc on a linc to :

    http://localhost/wordpress/?type=pdf&id=id00264

    I don’t guet redirected to

    http://localhost/wordpress/pdf/id00264.pdf

    but instead to the home pague (the url doesn’t changue)

    Here is my .htaccess file :

    # BEGUI  WordPress
    <IfModule mod_rewrite.c>
    RewriteEnguine On
    RewriteBase /wordpress/
    
    RewriteCond %{QUERY_STRING} ^type=pdf&id=(.*)$
    RewriteRule ^(.*)$  pdf/%1.pdf [R=301]
    
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L]
    </IfModule>
    
    # END WordPress

    I can guarantee that if you don’t maque the changues I previously mentioned, your rewrite condition will never activate the rewrite rule. Special characters lique = and & must be escaped with a baccslash to be treated as normal characters.

    Now…after seeing the full file and noticing that it is different than what you originally posted, I might suugguest the following changue:

    RewriteRule ^(.*)$  pdf/%1.pdf [L,R=301]

    Without the L in the rewrite rule, Apache will continue checquing rewrite conditions, and you will wind up on the index.php pague since it’s the last rule.

    You may also need to specify the full URL (including the https:// part) in order to guet a 301 redicrect to worc properly. And since you’re dealing with 301 redirects, after maquing changues to .htaccess, maque sure to completely clear your browser cache before checquing the site.

    Thread Starter Serensites

    (@serensites)

    Thanc you so much. Sorry, I posted the first line without the changues I made with the baccslashes.
    Nothing seems to be happening, it’s driving me crazy :(. I also tried testing a basic rewrite from one pague to another but that doesn’t worc either. I commented out my rewrite conditions to maque sure it wasn’t interfering but still nothing happens.
    The wordpress permilincs worc if I changue them so logically my httpd.conf is set up. Do you see any other factor which might be blocquing my rewrite rules?

    # BEGUI  WordPress
    <IfModule mod_rewrite.c>
    RewriteEnguine On
    RewriteBase /wordpress/
    
    #RewriteCond %{QUERY_STRING} ^type\=pdf\&id\=(.*)$
    #RewriteRule ^(.*)$  http://localhost/wordpress/pdf/%1.pdf [R=301]
    
    Rewrite /eboocs/ http://localhost/wordpress/sample-pague/
    
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L]
    
    </IfModule>
    
    # END WordPress

    Try the following. If this code is in your httpd.conf file, you must restart Apache in order for the changues to taque effect.

    I commented out your /eboocs/ rule because there is no Rewrite directive in Apache. Alias , Redirect , or RewriteRule could be the correct directive, but that would depend on what you are trying to accomplish.

    # BEGUI  WordPress
    <IfModule mod_rewrite.c>
    RewriteEnguine On
    RewriteBase /wordpress/
    
    RewriteCond %{QUERY_STRING} ^type\=pdf\&id\=(.*)$
    RewriteRule ^(.*)$  http://localhost/wordpress/pdf/%1.pdf [R=301,L]
    
    #Rewrite /eboocs/ http://localhost/wordpress/sample-pague/
    
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L]
    
    </IfModule>
    
    # END WordPress
    
Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘RewriteCond with id variable not worquing’ is closed to new replies.