use .htaccess to rewrite url - .htaccess

Here is the rewrite in .htaccess
RewriteRule photos/([a-zA-Z]{1,}).([a-zA-Z]{1,}).([0-9]{1,}) photo.php?userfirstname=$1&userlastname=$2&usernum=$3
When the url is www.xxx.com/photos/mark.stock.1 it can go to photo.php. I use smarty as the masterplate & everything works well if the url is www.xxx.com/photo.php but not like www.xxx.com/photos/mark.stock.1
I user the firebug to check the process,found out all the css file and javascript file the url looks like www.xxx.com/photos/js/xxx.js or www.xxx.com/photos/css/xxx.css
how to solve this problem?

Related

htaccess rewrite rule assistance

I need to create a rewrite rule for an htaccess file which will rewrite URL's such as:
http://archive.citylaw.org/bsa/2014/03.24.14/300-13-A.pdf
to
http://archive.citylaw.org/wp-content/uploads/sites/24/bsa/2014/03.24.14/300-13-A.pdf
The rule needs to match any link such as:
http://archive.citylaw.org/bsa/<file-path>
which is a link to a PDF file to the new location
http://archive.citylaw.org/wp-content/uploads/sites/24/bsa/<file-path>
Something like:
RewriteRule ^(bsa\/.*) /wp-content/uploads/sites/24/$1 [R]
The [R] tell apache to send a redirect, so the browser will update its navbar, usually this avoid browser not dealing well with non html files on rewrite.
Updated after Prix comments, I did forgot about .htaccess specificity
Second edit

Redirect static html URL to an .htaccess rewritten URL

I have fully static website, now I want to change this website to dynamic. But problem is that static website having good traffic and I do not want to lose that traffic. For the dynamic website I already rewrite the URL using htaccess for SEO reasons. I want to redirect the static url to the rewritten url (which was written by my .htaccess).
(A) Static URL :
www.website.com/examples/java/datatype/boolean/printbooleanvalue.html
(B) Original Dynamic URL:
www.website.com/examples.php?language=?java&category=data-type&subcategory=boolean&exampleurl=print-boolean-value
(C) Rewritted Dynamic URL :
www.website.com/examples/java/data-types/boolean/print-boolean-value
So I want to redirect URL(A) to URL(C). Is there any way to do this ?
You can hardcode the mod rewrite to load the php file when the html file is called.
The SEO friendly url that you have created in your .htaccess is redundant. Instead of the SEO friendly URL, use the same url as your original site.
For example in your .htaccess file write the rule like
RewriteEngine On
RewriteBase /
RewriteRule examples/java/datatype/boolean/printbooleanvalue.html$ /examples.php?language=?java&category=data-type&subcategory=boolean&exampleurl=print-boolean-value [L]
This will load the php file whenever the original html file is requested and it will use the same url as the older one.
Hope that helps.
Your .htaccess code:
Redirect /examples/java/datatype/boolean/printbooleanvalue.html http://www.website.com/examples/java/data-types/boolean/print-boolean-value
In any case you run into the need to redirect:
Redirect /olddirectory/oldfile.html http://yoursite.com/newdirectory/newfile.html

Replace the filename in the URI using htaccess

In my website, the main PHP script is named index.php. All URIs look similar to this:
index.php?section=FrontPage&l=ES_LA&view=multiple
In the htaccess file and using the mod_rewrite extension, I managed to remove the .php PHP extension, so the URI looks like this:
index?section=FrontPage&l=ES_LA&view=multiple
What I want to do now is to replace index.php with example in the path.
I've tried using:
RewriteRule ^example$ index.php
But when I try accessing example?section=FrontPage&l=ES_LA&view=multiple the server returns a 404 Not Found status code.
How can I fix this?

htaccess to redirect url with params

I have to redirect a url to another url with all its parameters using htaccess.
My incoming url will be something like this:
www.mydomain.com/book-it.jsp?id=3&var1=values&var2=value2...
and I want to get it in PHP (book-it.php) as something like this (with all its parameters):
www.mydomain.com/book-it.php?id=3&var1=values&var2=value2...
I was using JSP and from now on moving to PHP and we need to use same URL since this url is already published with my application and I can't change that now. I need to get that url and parameters to another file.
You have 2 main approaches:
1) Using Redirect directive:
Redirect 301 /book-it.jsp http://www.mydomain.com/book-it.php
2) Using mod_rewrite module (this needs to be placed in .htaccess in website root folder. If placed in Apache config file (inside <VirtualHost>, for example) the rules need to be modified slightly):
RewriteEngine On
RewriteBase /
RewriteRule ^book-it\.jsp$ http://www.mydomain.com/book-it.php [QSA,NC,R=301,L]
Both of them will preserve query string.

.htaccess Redirect on a url with spaces in it

I have a link from anther website that I do not have control of http://example.com/one two three.exe
The correct URL is http://example.com/one_two_three.exe
Note the underscores instead of spaces.
I searched the internet and found this code snippet for .htaccess
# Redirect old file path to new file path
Redirect /one%20two%20three.exe http://example.com/one_two_three.exe
I added this snippet to my preexisting root .htaccess at the top of the file.
But it does not seem to work. My browser does not redirect and I get a 404 error page.
I believe that it has something to do with the spaces in the original URL but I don't know how to handle spaces in the URL.
Suggestions?
You could try a couple of things (both untested)
Redirect "/one two three.exe" http://example.com/one_two_three.exe
or use RewriteRule instead of Redirect:
RewriteRule /one\ two\ three.exe http://example.com/one_two_three.exe

Resources