Simple rewrite with subfolder - mod-rewrite

I want to point:
www.reneebuller.com/paintings/busy-pair-humming-bird-painting.html to
www.reneebuller.com/painting-details.cfm?ID=136&Type=Bird
Is this the correct rewrite? I'm not sure how to account for the /paintings/ folder.
RewriteRule ^paintings/busy-pair-humming-bird-painting.html painting-details.cfm?ID=136&Type=Bird [NC, R=301, L]

The above rewrite is correct. It just takes time for the server to process the .htaccess file.

Related

Mod Rewrite Sub Folder Structure to GET Variable

How would I write a url such as the following
www.linku.biz/profile/jacktrow
to
www.linku.biz/profile/?us=jacktrow
Being 'jacktrow' can be just letters (a-Z)
What would be the complete code I can place in a .htaccess in the directly of profile?
Much appreciated, mod rewrites and .htaccess are just such a pain!
First, make sure mod_rewrite is enabled.
Then, put this code in your htaccess (in root folder)
RewriteEngine on
RewriteRule ^profile/([a-z]+)$ /profile/index.php?us=$1 [L]

Mod Rewrite Rule redirects

I was trying to password protect a folder on our server. However, each time I included .htaccess to that folder, and .htpasswd, it was automatically redirecting everyone to a 401 page without any login prompt.
When i visited my root directly, i saw this .htaccess:
RewriteBase /
RewriteEngine on
#RewriteCond %{HTTP_HOST} ^www\.(.+)
#RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
#RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]
I commented it out and my .htpasswd & .htaccess to the foldr works, however, as my mod rewrite isn't the best, I wasn't sure if commenting the above will create problems for my website?
thanks.
This is basically just redirecting any www.host.ext to host.ext, and returns a 301 Moved Permanently response code.
If you don't care about that functionality you should be able to comment it out.
post your subdirectories htaccess file and we can see if we can sort your original issue out.

.htaccess will not redirect .php files

I have this in my htaccess, standard domain redirection:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ "http\:\/\/fullnewdomain\.org\/$1" [QSA,R=301,L]
And it works fine for folders, subfolders, html files, images, etc. However, for some reason it refuses to redirect php files. Instead they still run as normal and do not redirect to the new domain. Any ideas as to why, and how I can fix it? It's almost like this host is trying to execute the php file before checking any rules ( And I'm not sure what I could do if that's the case! ).
Turns out there was an htaccess file the host had placed in the home directory ( One level above public_html ) to "counter" bots, but all it did was break anything else that tried to apply a rule to php files. Removed the file, problem solved itself.
For reference, hostgator was the host, and I still don't know why they felt the need to place the file there in the first place.

mod_rewrite from a subfolder with a querystring to a folder or file

I am trying to redirect from:
http://www.example.com/folder/product.aspx?prodid=146
to
http://www.example.com/folder2/folder3/
The folders referred to here don't really exist. There are other rewrite rules in place which redirect transparently to the actual content.
If I create a directory called 'folder', and put an .htaccess file in it, I can get the redirect working, BUT, other URLs which refer to that folder no longer work. So I have to try and do the redirect from the .htaccess file in the ROOT folder.
I tried this:
RewriteCond %{QUERY_STRING} prodid=146
RewriteRule ^/folder/product.aspx$ /folder2/folder3/? [R]
...but it doesn't work (I get a 404 error). Using identical syntax but omitting the /folder/ from the 2nd line works if the .htaccess is in the folder directory (so I know the above can't be too far off) - but as I said, I cannot do that. I have tried lots of variations but nothing seems to work. Any assistance appreciated.
You need to remove the slash from the start your URL regexp. Like this:
RewriteRule ^folder/product.aspx$ /folder2/folder3/? [R]

Rewriting URLs and "faking" folders

I'm trying use mod_rewrite to rewrite URLs from the following:
http://www.site.com/one-two-file.php
to
http://www.site.com/one/two/file.php
The folders don't exist, but "virtually" exist for the rewriting purpose.
What rule do I used in this?
Untested:
RewriteRule ^([^/]+)/([^/]+)/([^/]+)\.php$ $1-$2-$3.php [L]
I can't really understand your explanations about virtuality and existence: one-two-file.php must exist or you'll have nowhere to redirect to.
Update
The previous version works fine when used from an .htaccess file. However, if used from main http.conf file you need to add leading slashes:
RewriteRule ^/([^/]+)/([^/]+)/([^/]+)\.php$ /$1-$2-$3.php [L]
I presume that's why it wasn't working for the OP (he was probably getting a 404 not found status code).

Resources