I was trying to rewrite a url in apache but it is not working as i expected. Here is how i defined in local environment
Allow from all
Satisfy Any
RewriteEngine On
RewriteOptions Inherit
RewriteRule ^(.*/)?email/?$ /api/v1/email [R=permanent,L]
I have defined this rewrite condition in mycompany.conf file which is located in the path
/etc/apache2/other
The url coming is "POST /items/50d42529dbc38e3d580002ff/email HTTP/1.1" 500 18750
I want to redirect /email to another path like /api/v1/email
I have defined a rails routes path for /items/50d42529dbc38e3d580002ff/email like this
match 'items/:id/email' => 'items#email', :as => :email_item, :via => :post
My question is based on rewrite rule it should go to api/v1/path and it shouldn't go to rails path that i defined in routes. It is not working like i thought.
I want to know whether my rewrite rule is correct or not and also i didn't define in .httaccess file. I included mycompany.conf file httpd.conf so i think it doesn't have a problem.
Please help me in this issue. Thanks in advance.
Related
I have site:
mysite.com/welcome
I wan't to remove the welcome-part of the url, but only IF the part is == welcome
for example:
mysite.com/welcome => mysite.com/
mysite.com/contact => mysite.com/contact
In any other case, the name after mysite.com stays the same.
I know it has something to do with the .htaccess-file on my server, but I can't figure out
how exactly I have to realize it. I assume I have to use regular expressions?
Thanks for any help
You can use this rule to remove welcome only:
RedirectMatch 301 ^/welcome$ /
Place this rule in your root .htaccess.
I'm trying to rewrite all files located below a URL such as:
http://www.example.com/one/
to a new URL:
http://www.newhome.com/new/
So, the desired functionality is to have http://www.example.com/asdf and http://www.example.com/ both remain on www.example.com, but http://www.example.com/one/test/index.php would pull content from:
http://www.newhome.com/new/test/index.php
I can't quite get the correct rewrite rule to do this. Any ideas?
EDIT: The rewrite rule needs to have requests from http://www.example.com/one/* retain the URL in the browser, but pull content from http://www.newhome.com/new/test/* (the rewritten locations will include forms and form submissions).
Of note, the .htaccess file will go in the equivalent of the '/one' directory (because of server access restrictions)
Thank you
Put this rule as your first rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^one/.*$ /new/test/index.php [L,NC]
I have a domain like example.com where root directory is web.
I have created a subdomain happy.example.com where directory is outside web folder called happy and connected it to happy.example.com.
My webpage tree looks like
happy
web/images
So all my images for root directory are stored in (web/images)
example.com/images
So a full path to an image can be
example.com/images/me.png
Now i have created a sudbdomain which i call:
happy.example.com
What i would like to do is if i type
happy.example.com/images/me.png
then i should be able to see the picture.
So somehow i need to link all images folder to a subdomain from root directory in web.
I hope you guys got my question.
I guess i shoud have an htaccess file with all funny stuff in happy folder?
Cheerz
Since the two document roots of your two domains aren't connect to each other (one inside the other, or the same), you'll need to either redirect or proxy, or, use a script.
To redirect is easiest, but it'll change the URL in the browser's location bar:
Redirect 301 /images http://example.com/images
or using mod_rewrite:
RewriteEngine On
RewriteRule ^images/(.*)$ http://example.com/images/$1 [L,R=301]
To proxy, you need to have mod_proxy loaded, which isn't always the case if you're using a webhost or hosting service. But you can use the P flag in mod_rewrite to do this:
RewriteEngine On
RewriteRule ^images/(.*)$ http://example.com/images/$1 [L,P]
The last option is to route all image request to a script, like a php script or something. And the script itself returns the image:
RewriteEngine On
RewriteRule ^images/(.*)$ /load_image.php?image=$1 [L]
then you'd have something like:
<?php
header("Content-type: image/jpeg");
readfile('../web/images/' . $_GET['image']);
?>
Obviously, you'd need to check the extension and return the correct content type depending on the image type.
I am currently trying to put a RewriteRule into my .htaccess file for my Magento website that will allow me to write a category URL in the following way:
http://mydomain.com/dir/<direction>/order/<order>/<Magento category URL path>.html
What I am basically looking to do is use my robots.txt file to make some of the category URLs not appear (specifically when you apply a different sort order to the category).
So let's assume I have the following URL:
http://mydomain.com/dir/asc/order/sales_index/footwear/mens-work-boots/motorcycle-boots.html
I would like that to be rendered just as if it the URL was:
http://mydomain.com/footwear/mens-work-boots/motorcycle-boots.html?dir=asc&order=sales_index
The code I have put in my .htaccess file is as follows:
RewriteRule ^dir/(.*?)/order/(.*?)/(.*?)$ $3.html?dir=$1&order=$2
For some reason, when I have this in there, I get a 404 error. Can someone point me in the right direction to make this work for me?
I tried with this on my server
RewriteRule ^(.*)/dir/(.*?)/order/(.*?)/(.*?)$ $4.html?dir=$2&order=$3 [R,L]
and when i issue request
http://myserver/dir/asc/order/sales_index/footwear/mens-work-boots/motorcycle-boots.html
i get proper redirection to
http://yuave.dev:81/footwear/mens-work-boots/motorcycle-boots.html.html?dir=asc&order=sales_index
May be you are missing [L] flag on your request.
I've been puzzling over this none for a while. This is the rewrite rule that I've got at the moment:
Options +FollowSymlinks
DirectoryIndex index.php
RewriteEngine on
RewriteRule ^ext\/(.*)$ index.php/cproposal/key/$1 [NC]
Essentially I'm trying to get
http://localhost/cvc/ext/12445345346
to rewrite to
http://localhost/cvc/index.php/cproposal/key/12445345346
Codeigniter is producing a 404 however. If I change the index.php/cproposal/key/$1 part of the rule to something inane like the Codeigniter license.txt thats found in the directory then it works but anything actually related to Codeigniter itself produces a 404.
Any ideas where I'm going wrong?
mod_rewrite is great, but Codeigniter already has a built in solution for anything in your Codeigniter application.
Try adding this to your config/routes.php:
$route['ext/(:num)'] = 'cproposal/key/$1';
This would route requests for:
http://localhost/cvc/ext/{any_number}
to
http://localhost/cvc/cproposal/key/{requested_number}
The index.php will be optional, and dependent on your CI configuration. In other words, if you're using it already - it will be in the url. If not, it doesn't have to be.
All CI routes may use regular expressions in addition to the built in wildcards (:num) and (:any), so feel free to get creative.