how can I do a redirect using Apache mod_rewrite with this rule? [closed] - isapi-rewrite

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I cannot get the page to redirect to product_detail.do, the page is staying on product_detail.asp
I need links from our old asp site to redirect properly to the new Java site.
How can I fix the below rule? What do I need to do differently? Thanks.
RewriteCond %{QUERY_STRING} T1=([^/]+)
RewriteRule ^/product_detail.asp /product_detail.do?q=%1 [R=301,L,NE]
Correction, I am using Apache mod_rewrite. Thanks again.

depending on the config file u're using, you might just need to get rid of '/' in front:
RewriteCond %{QUERY_STRING} T1=([^/]+)
RewriteRule ^product_detail.asp /product_detail.do?q=%1 [R=301,L,NE]

Related

Redirect subdomain to user profile

I'm trying to redirect a subdomain user to his profile.
For example: If user requested user.example.com
he gets redirected to example.com/user
I searched a lot, and most answers were old and didn't work.
Things I have done:
Created A record with *.example.com.
Enabled wildcard redirect to example.com (I actually don't know if
this is needed) some Stack Overflow answer provided that.
Created subdomain in my hosting like *.example.com (but this caused
all my subdomains get redirected to the main landing page, which is
example.com) some Stack Overflow answers provided that.
In my larave project routes.
Route::domain('{name}'.'example.com')->group(function () {
Route::get('/{name}', 'usersController#profile');
});
Route::group(['domain' => '{account}.example.com'], function () {
Route::get('/{name}', 'usersController#profile');
});
I'm really lost between old Stack Overflow answers and PHP hard code. All I want is simple. If user requested user.example.com he gets redirected to his profile example.com/user then he can navigate normally like no need for subdomain later.
I don't know what I'm missing or doing wrong!
Glad to know this this worked out for you. Here i am dropping a formatted answer of it. Can help others.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [NC]
RewriteRule (.*) example.com/%1/$1 [L,R=301,QSA]
This worked for me.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)$ /%1/$1 [L,NC,QSA]

Differentiate embedded "<img src='http://example.com/xxx.jpg'>" and direct "http://example.com/xxx.jpg"? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Is it possible to differntiate between an embedded HTTP request to an image as in <img src='http://example.com/xxx.jpg'> and a direct image access as in http://example.com/xxx.jpg?
I do a htaccess redirect using HTTP_REFERER in case a request comes from outside my domain to add a water sign to the pictures. Only in case of a direct access, I'd like in addition show a HTML page with some hints.
I used HTTP_ACCEPT for that. When it started with image/ then it was an embedded access. Otherwise it was a direct access. This does not work anymore. I always get */*.
Any idea how to achieve that (in PHP)?
Thanks!
There is a way that should work in most modern Browsers, but there is no quarantine. Because Browsers tend so send a HTTP header called "referer" if a resource is requested, we could select based on this. So if the referer is equal to your domain than we have no direct access.
# Check if the URI is a physical file
RewriteCond %{REQUEST_URI} -f
# Check if the file has any kind off Image extension like:
# .gif .jpg .jpeg .tif .tiff .png .svg .bmp (case insensitive => [NC])
RewriteCond %{REQUEST_URI} \.(gif|jpe?g|tiff?|png|svg|bmp)$ [NC]
# Check if referer is empty
RewriteCond "%{HTTP_REFERER}" ^$ [NC]
# Direct access
RewiteRule ^.*$ /direct_access.html [L]
# Check if the URI is a physical file
RewriteCond %{REQUEST_URI} -f
# Check if the file has any kind off Image extension like:
# .gif .jpg .jpeg .tif .tiff .png .svg .bmp (case insensitive => [NC])
RewriteCond %{REQUEST_URI} \.(gif|jpe?g|tiff?|png|svg|bmp)$ [NC]
# Check if referer is not own domain
RewriteCond "%{HTTP_REFERER}" !^https?://(www\.)?example\.com [NC]
# External access
RewiteRule ^.*$ /image_water_sign.php [L]
This works for www and non-www as well for http and https just change example\.com to your e.g. domain\.org
The RewiteRules are just examples.
Just one Remark: This is not a absolute protection if you want to protect your images from direct download. Faking the HTTP header with this data is very simple.

Mod_rewrite has different result on Windows and Ubuntu [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have set the following rewrite rule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ core/index.php [L]
and the site architecture is
newsite
﹂ .htaccess
﹂ core
﹂ index.php
If I use the url: http:// localhost/web/newsite/test on Windows
it will redirect to /web/newsite/core/index.php
and it work!
but if use the url http:// localhost/~user1/web/newsite/test on Ubuntu
it will redirect to /home/user1/public_html/web/newsite/core/index.php
not /~user1/web/newsite/core/index.php
So, how can I solve this problem?
Thanks!
Add a RewriteBase above your rules:
RewriteBase /~user1/web/newsite/
Apache on ubuntu is tries to guess if the rewrite rule's target is a URI-path or a file-path and it's guessing incorrectly so you have to tell it what the real relative URI base is.

Mod_rewrite help for wordpress

I have a wordpress site that has a very big database. There are many cases of typo errors in the title and slugs. I normally do a search and replace to correct the typos.
Can anyone help me in mod_rewrite rules to 301 redirect my old URL to the correct URL?
my site is using the following structure:
www.domain.com/shop/xxx-blackk-xx-xx
www.domain.com/shop/blackk-xx-xxx
www.domain.com/shop/xxx-xx-blackk
How do i redirect the old URL above (with typo) to the new URL (after corrected to black).
Your help is much appreciated!
Thanks.
Could you not just use a find-and-replace on the url?
RewriteRule ^(.*)blackk(.*)$ $1black$2 [R=301]

mod_rewrite: Rewrite root to somewhere else [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 12 years ago.
I'm trying to rewrite URLs to a generic show_page.php script, but I'm having trouble redirecting the root URL. I've been searching Google and stackoverflow but all I've come across implies that ^$ will redirect the root, but for some reason it doesn't. All I get is a 403 Forbidden (since I have indexes turned off).
Here's my current .htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) /show_page.php?url=$1 [QSA,NS]
Other URLs redirect perfectly, and if I change the rule to:
RewriteRule ^$ /show_page.php?url=/ [QSA,NS]
I still get the 403.
Sorry, I've just realised my mistake, the rewrite conditions were stopping it from working, doh!

Resources