I have been trying for DAYS to get a RewriteRule to work on my site and every time I figure it out it works reverse (in other words it generates a new url that directs back to the old url. 2 reverse examples: RewriteRule ^([^/]+)/([^/]+)\.html$ pages/companyprofile.php?recordID=$1/$2 [R=301] RewriteRule test(.*)\.htm$ /pages/companyprofile.php?recordID=$1 [R=301,L] The link that I want to rewrite is (where 7 and voiparty are automatically generated): mysite.../pages/companyprofile.php?recordID=7/voiparty End result being mysite.../7/voiparty.html If there is any way that you can help me that would be amazing. I am obviously missing something. Common sense tells me just to switch the 2 but it always results in errors. I NEED YOUR HELP!!!! THANK YOU SO MUCH IN ADVANCE!
RewriteEngine on RewriteRule ^(\d+)/(.+)\.html$ pages/companyprofile.php?recordID=$1/$2 [L] Code (markup): Should do it, that's if I understand what you want. As you have had it redirecting you might find it still redirects in which case you need to clear your browser cache.
Tolra, thank you so much for your help I put that in my .htaccess file and it does the same thing the others are doing. Without putting R=301 as a flag it shows up as a direct link but the old link doesn't redirect to it. So I then put [R=301, L] and the newly generated link redirects to the old one. From what I understand a RewriteRule should take the old link and redirect to the new link. Do you have any idea or suggestions of what I am doing wrong? THanks again!
With the [R] it will redirect, I thought you wanted to just call the script on passing parameters based on the URL. Can you post an example of the URL typed into the address bar and an example of the URL that will be redirected to, that way I hope I can understand were you are trying to get to. If there's more than one case please give me examples of each.
I'm sorry, I am new at all of this. Again, thanks for your help! The URL that I have now is www mlmrank com/pages/companyprofile.php?recordID=7/voiparty The URL that I want it to redirect is www mlmrank com/7/voiparty.html
What I have gotten so far is the newly generated link that I want but with the 301 redirect it is redirecting me back to the old URL, I need the old url to redirect to the new url. I left the code in that you gave me so you can see if you go to my new url that it redirects to the old one (with R=301 in the code). THANK YOU TOLRA!!! I am so grateful for your help!
Remove the redirect I gave you before from .htaccess, then put a .htaccess in your pages folder: RewriteEngine on RewriteCond %{REQUEST_URI} ^/pages/companyprofile\.php$ RewriteCond %{QUERY_STRING} recordID=(\d+/.+) RewriteRule .* http://www.mlmrank.com/%1.html? [R=301] Code (markup): That redirects the ?recordID=7/voiparty version to 7/voiparty.html version.
So I did what you said. I removed the code that you gave me originally and created a new htaccess file in my pages folder. Then I put the code above in it. It does redirect to the link that I want but I get a 404 not found error. I am going to leave it up (I can't leave it up for long but I will try so you can see). I am guessing the page is redirecting to a link that hasn't been created? I really am not sure though. Tolra, your help is SOOOOO much appreciated! What are your thoughts?
You don't appear to have a file or script for /7/voiparty.html so as there's nothing there you get the 404. Off the top of my head, in your top level .htaccess put: RewriteEngine on RewriteRule ^(\d+)/(.+)\.html$ pages/companyprofile.php?recordID=$1/$2 [L] Code (markup): Put the .htaccess from above in your pages folder and see what happens, it might loop horribly and crash but give it a try. If it doesn't work I'll have another look at the rules as I understand what you are trying to do now.
I added that code to my top level .htaccess file and when I go to one of the links I get a warning saying the page isn't redirecting in a way that it will never complete. I am guessing that is a looping problem?
In your root .htaccess RewriteEngine on RewriteRule ^(\d+)/(.+)\.html$ pages/companyprofile.php?recordID=$1/$2 [L] Code (markup): In the .htaccess in pages folder RewriteCond %{THE_REQUEST} !^[A-Z]+\ /\d+/.+\.html\ HTTP/ RewriteCond %{REQUEST_URI} ^/pages/companyprofile\.php$ RewriteCond %{QUERY_STRING} recordID=(\d+/.+) RewriteRule .* http://www.mlmrank.com/%1.html? [R=302] Code (markup): It's working on my test server but let me know how you get on with it.
YOU ARE AMAZING!!!!!! I AM SO GRATEFUL FOR ALL OF YOUR HELP! I am basically in tears right now. Thank you so much, everything is working exactly as I hoped. THANK YOU!!!!!!!!