.htaccess - route to selected desination but change browser url - apache

Problem:
I'd like to accept the original request. Say its, /IWantToGoHere/index.php
but I want to return to the browser, /GoHere/index.php
To be clear:
I actually want to send the original request location down to the script requested, however, I want to return the user a browser URL to another destination.
Code:
RewriteEngine on
RewriteRule ^(.*)IWantToGoHere\/\.php$ GoHere/index.php [NC,C]
RewriteRule ^GoHere/index.php$ GoHere/index.php [R,NC]
Notes:
I realize the code above doesn't work. I've tried a number of different calls. I spent umpteen hours yesterday trying every clever solution I could pull out of my limited mod_rewrite knowledge bank. Based on my understanding of mod_rewrite, I don't think it's do able. I understand its not what the preprocessed was designed to do. At least not from anything I could find on the Apache web site. I've been told that if I could dream it up, that it could be done:) I was wondering if anyone had and ideas how to get it to work.
Why would you want to do that?:
Because I do. No really, I want the URL returned to the user for further processing.
weez

If I understand the question correctly, to accomplish this you'll need to send a header from /IWantToGoHere/index.php that redirects to /GoHere/index.php once the script is finished executing. That is, if you want Apache to still call IWantToGoHere but return to GoHere. So at the end of processing for IWantToGoHere script something like this:
header('Location: /GoHere/Index.php');
Which will redirect correctly.

Related

Rewriting Link with mod-rewrite

I have a link being sent to users in one format, but I need to make sure it passes through a main index page for login purposes. I figured mod rewrite was the way to go.
Link being clicked on by user:
https://sub.domain.com/link/link.jsp?pageId=1234567&id=12345
Where it needs to go:
https://sub.domain.com/index.html?o=(full original URL from above, including query string)
The o= in this case will let the user login and pass them along to that original URL. Now, there are also some images and a style sheet involved, so I need to have the rewrite ignore them.
After reading documentation and a number of code examples (many from this site), I tried to just get a basic code going to see if my rewrites will even work, as I'm new to this.
This appears to force the URL to rewrite but isn't passing the user along to the original link:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub.domain.com [NC]
RewriteRule .* https://sub.domain.com/index.html?o=%{HTTP_HOST}%{REQUEST_URI}?%{QUERY_STRING} [L]
Also please note this is all going inside a virtual host, not htaccess. As I said, the code above appears to redirect when I test it, but it might be unintended and not at all how I should write it.
I also tried adding in this code for images/stylesheet ignores
RewriteCond %{REQUEST_URI} !\.(css|jpg|jpeg)$ [NC]
At that point everything went crazy, but I know it's because I'm slapping code together and thinking it's going to work. From that point I tried a lot of changes, but most resulted in a loop condition and I kept falling back to square one (original code you see above). Apologies for the long winded post, but I'm hitting my head against a wall at something I thought wouldn't be difficult. Obviously, despite reading, I'm lacking some understanding. Any guidance would be very helpful.
The problem with your current solution is: an URL is only allowed to have one ? inside.
Note that your code will send a redirection status code to redirect inside the browser, because you provided a FQDN. Try doing an internal redirect by just using /index.html?o=.... If that doesn't work either (not sure right now), URL-Encode the second ?
[Edit]: rewrite, guess I got the question wrong.

can't figure out mod_rewrite for certain pretty url

I am having trouble figuring out how to write this condition I am wanting in my .htaccess file.
I have tried multiple different ways with no success but, here is what I am trying to accomplish. Using apache.
My current url is like this: http://site.com/page?id=123&variable=a-text-like-this
I am wanting to turn it into this: http://site.com/differentpagename/a-text-like-this/
I want to hide the name of the real page and the id and its value.
can someone please help ive spent all night trying to figure this out.
This will do what you want. But beware, that id is hard-coded in .htacess, which is very bad. So, you'll need a line for every alias. That's why I asked about transfering alias to id in the script.
RewriteEngine on
RewriteRule differentpagename/a-text-like-this/ /page?id=123&variable=a-text-like-this [L]

Rewrite URL using DSAPI

I need to rewrite URL. i.e. when user send request for 'url1' we will do request to 'url2' ('url1' will not be changed in browser, users should not know anything about that). I've looked a bit around and did not find another solution but DSAPI filter. DSAPI can do what I need, however due to low experience I can't complete that task.
Can somebody suggest me what events should I look into? and what exactly should I do..
I was looking on those events: kFilterStartRequest, kFilterRawRequest or kFilterRewriteURL no success yet.
I've just complete my solution based of DSAPI, please read here how to rewrite URL using DSAPI.

Simple mod_rewrite, replace one word in every instance

I've been looking for an answer to this forever and can't find it, yet it seems like it should be so simple!
I want to use mod_rewrite to replace a word in a url in every instance that it shows up, but I don't want a redirect to happen, just changing the way the url appears to site users.
Example:
Change
mysite.com/something/groups/anything...
to:
mysite.com/something/projects/anything...
I know I could go through and start tweaking files but mod_rewrite would work much better because I'm sure I'll mess something up otherwise (for reference I'm using joomla/jomsocial).
RewriteEngine On
RewriteRule something/groups/.*$ something/projects/$1

Dynamic URL Rewriting with IIS6

I've been tasked with making an already existing e-commerce site SE friendly - which in this case means (amongst other things) letting the user change the URL for each page/product through the back end.
The site is an old asp site running on IIS6. I've started looking into http://www.codeplex.com/IIRF and http://www.helicontech.com/isapi_rewrite/ , but I'm a bit dubious about how to let the user change the URLS without them going into the server and hard coding them.
Ionic's Isapi Rewrite Filter runs from a .ini file, so I'm thinking that I will get the back end of the site to write to this ini file based on form inputs.
Does anyone have any experience or advice with regard to this?
edit:server is dedicated
By change URL fro each page, I think you mean change slug, or do you actually mean URL.
Slug: www.somesite.com/products/{slug}
URL: www.somesite.com/{url}
Here is how I would do it.
Give an original structure like this:
www.somesite.com/products.aspx?id=23
with an end goal of it to look like
www.somesite.com/products/the-product-to-be-sold
Or better yet
www.somesite.com/products/23/the-product-to-be-sold
I would create a rule that looks like this.
RewriteRule /products/([0-9]+)/(.*) /products.asp?id=$1&slug=$2 [NC]
That way you don't have to change anything, the name is in the URL for SEO optimization, and the ID is still there too.