.htaccess redirect with a variable? - .htaccess

I need your help.
I want to redirect a URL like:
http://test.mydomain.com/tag/4
to
http://test.mydomain.com/tag/tag.php?id=4
The number is a variable and can change of course. Hope you have a solution for me.
RewriteEngine On
RewriteBase /tag
and now?..
I'm a total newbie in .htaccess!
Thanks for your short help

Simply add this line to your .htaccess file
Redirect 301 http://test.mydomain.com/tag/4 http://test.mydomain.com/tag/tag.php?id=4
This is best done using the pages path. Here's an example:
Redirect 301 /tag/4.html http://test.mydomain.com/tag/tag.php?id=4
This should give you all you need http://www.htaccessredirect.co.uk/
Given that you're talking about redirection from said page using what the user types:
Create a text box and a button like this <button onclick="redit();">
Then add this function
<script type="text/javascript">
function redir(){
var page = document.getElementById("textArea").value;
location.href = "http://test.mydomain.com/tag/tag.php?id=" + page;
};
</script>
This will send the user to the page you want them to, based on what they selected as page number.

Related

How to redirect Hard Coded Urls to hard coded Urls without hitting errorAction?

I have almost one thousand links which I want to redirect when a request is made specifically to those URLs. e.g
Redirect http://serverAddress/app/2017/06/09/8-20-taraweeh/ http://serverAddress/app/prayer/8-or-20-Rakat-for-Taraweeh
I am trying this code in .htaccess file but the problem is that when I enter the Url, instead of hitting the .htaccess code it first hits the Yii app and check if the Url exists, if not exists(definitely does not exist) it takes me to the error page.
Now I cannot define a rule because as you can see the URL after the app is changing, I cannot define a generic rule. So I have to hard code in my yii2 app.
Question:
How to Hard code Url redirections in yii2?
You could define a rule something similar:
'<year:\d+>/<month:\d+>/<day:\d+>/<title>' => 'site/redirect'
Then in your SiteController use can use redirect in the controller action:
public function redirectAction($year, $month, $day, $title) {
$newUrl = .... // compute new URL based on the parameters
return $this->redirect($newUrl, 301);
}

Redirect parent not childs htaccess

In my magento module there is an extension.
Some urls like
http://www.domain.com/abc/p#abcs.html
http://www.domain.com/abc/p#xyz.html
etc
But when browsing http://www.domain.com/abc/p -> lead to blank page
I do not need http://www.domain.com/abc/p url
Is anybody help me
I want to redirect the url http://www.domain.com/abc/p to 404 page
without affecting its childs
ie
1. http://www.domain.com/abc/p#abcs.html
2. http://www.domain.com/abc/p#xyz.html
Points to its current position and
http://www.domain.com/abc/p to 404
Any help apperciated
Based on your comment it seems http://www.domain.com/abc/p#abcs.html shows proper content but http://www.domain.com/abc/p shows blank page.
In that case you can't do that via .htaccess because on server side URL will always be: http://www.domain.com/abc/p.
You need to put some custom Javascript in your page and redirect to some non-existant page (resulting in 404) by checking location.href using your Javascript.

301 redirect will not work with %20 in url

I am trying to create this redirect:
Redirect /commercial%20work.html http://nataliearriolaphotography.com/fine-art-photography-prints.html
The problem is that when I first created this page I left a space in the file name. In other words it was "/commercial work.html". In chrome and safari the url reads as above with the %20 in place of the space, but when I create this redirect it does not work. I have also tried the following:
Redirect /commercial work.html http://nataliearriolaphotography.com/fine-art-photography-prints.html
This does not work either. It causes a server error page to appear. Does anyone have any suggestions? Thanks!
Try adding quotes. So
Redirect "/commercial work.html" http://nataliearriolaphotography.com/fine-art-photography-prints.html
Put the page name in quotes should do it, for example:
Redirect 301 "/commercial work.html" http://nataliearriolaphotography.com/fine-art-photography-prints.html

.htaccess correct format for RewriteRule

I have a "JQueried" page using tabs - Tab A, Tab B etc the tabs hide/show content based on a link like this: Tab 1 I am using jQuery Address Plugin v1.4
http://www.asual.com/jquery/address/ to create new page titles and a new URL for each tab. If you do not know the Address Plugin recreates the URL so the link #tab1 creates the URL page.html#tab1 but without a page refresh. It also changes the page title but is there any way to create an RewriteRule so that http://domain/page.html#tab1 can be called by say http://domain/tab1.html (where tab1,tab2 etc. have proper names not tab!)
Have tried but don't seem to get it to work. e.g.
Options +FollowSymlinks
RewriteEngine on
RewriteRule about.html /test.php#tab1 [NC]
suggestions please. Thanks in advance - oh the htaccess will go in the actual root folder
Sorry, I checked \#, it didn't work for me either.
How about redirecting to test.php?hash=tab1, and then:
if (isset($_GET["hash"]))
header ( "Location: test.php#".$_GET["hash"] );
Based on my comment above - I have just found this stackoverflow.com/questions/8606127/mod-rewrite-hash-tags so I guess can't be done –

Multiple subdirectory error with mod_rewrite

I am trying to use mod_rewrite manually in joomla, and I have the following Rule:
RewriteRule ^test/(t1|t2|t3)-(.*).html$ /index.php?option=com_jumi&fileid=39&$1=$2 [L,NC]
So that I want the url
http://www.mysite.com/index.php?option=com_jumi&fileid=39&t1=foo
be displayed like
http://www.mysite.com/test/t1-foo.html
The rule works correctly, but when I am in the rewritten page the links like
http://www.mysite.com/link.html
or
http://www.mysite.com/xxx/link.html
become
http://www.mysite.com/test/link.html
or
http://www.mysite.com/xxx/test/link.html
respectively.
any suggestions?
thank you
You are using relative urls in your page. Your page contains a link like <a href="link.html">... and the browser makes the links relative to the current 'folder', namely "test", so when clicked the browser loads /test/link.html.
You should just use root-relative urls. So the link should become more like <a href="/link.html">.... The leading '/' makes the browser load the page relative to the root ("/"), not relative to "/test/".

Resources