hi i read all of other questions but i cant resolve my problem.
i setup my joomla website in this url: https://www.example.com/new
and now i want reditect this to (https://www.example.com) with my data for example i want reditect example.com/new/all-ads-smart/103-Hotels or other to example.com/all-ads-smart/103-Hotels
also i test this but it dont work
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^new/(.*)$ https://www.example.com/$1 [R=301,L]
this just work when i open (https://www.example.com/new) and redirect me to (https://www.example.com) and when open this (https://www.example.com/new/ads.php) i give 404 error
in end i sorry for my bad english<3
my data is:
new/all-ads-smart/103-Hotels
to
/all-ads-smart/103-Hotels
RewriteRule ^new/(.*)$ https://www.example.com/$1 [R=301,L]
This actually looks OK and should "work", providing it is in the root .htaccess file and located near the top of that file. However, if you still have a .htaccess file in the /new subdirectory then this is likely to override the directive in the parent .htaccess file - so it won't do anything.
However, it would be preferable to do this in the /new/.htaccess file instead (and keep the parent .htaccess file clean). For example, remove everything in the existing /new/.htaccess file and simply have an unconditional redirect:
RewriteEngine On
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
This will override the parent .htaccess file and when anyone visits the /new subdirectory they will be redirected. (This uses mod_rewrite, as opposed to a mod_alias Redirect to ensure that it overrides the parent .htaccess file.)
Related
I want to configure the .htaccess file to work the following way:
If the visitor tries to open a url with an existing folder name, redirect to main page (index.html).
I have the following rules for that:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !/index.html$ [NC]
RewriteRule ^data/existing-folder-1$ https://example.com [R=301,NC,L]
RewriteRule ^data/existing-folder-1/$ https://example.com [R=301,NC,L]
RewriteRule ^data/existing-folder-2$ https://example.com [R=301,NC,L]
RewriteRule ^data/existing-folder-2/$ https://example.com [R=301,NC,L]
</IfModule>
And it's working fine.
If the user tries to open a forbidden type of file (like .php), send to 403.
RewriteCond %{HTTP_REFERER} !^https://example.com [NC]
RewriteRule \.(php|log|htaccess)$ - [F,L,NC]
And it's also working fine.
I don't want users to see the contents of the folders, so I have this line:
Options -Indexes
I think that's all the important details to see the background.
I have a /rd folder with a simple index.php file to redirect URLs:
$url=$_GET["url"];
if (empty($url)){
//
} else {
header("Location: " . $url, TRUE, 308);
// later on with special functions
exit();
}
Such a link on my page looks like this:
https://example.com/rd/?url=https%3A%2F%2Ffoo-bar.com%2Fexample
Please note, that index.php is not written after /rd/ and before ?url. But if it's easier to solve this issue, I can modify it.
And now the problem comes here:
When I click on such a link through my website, it works perfectly.
But when I copy this redirect-link, and try to open in a new tab/window, it says 403 Forbidden. I think because #2 rule to disable access to .php files outside my domain.
Since I want to share those redirect links, I want them to be able to open when copy-paste the links.
I also don't want anyone to access any of my .php files - so it's not an option to remove rule #2.
How can I solve this issue? How can I enable to use the redirect links "alone", while keeping the rules to prevent access to files/folders?
Thank you.
I'm trying to bulk redirect my site link like this,I need to remove home from every link and redirect it to root directory as shown below.
example.com/home/hello-world.
example.com/home/tag/world.
to
example.com/hello-world
example.com/tag/world.
I'm using these code
RewriteEngine On
RewriteCond %{REQUEST_URI} (.+)/home(.*)$
RewriteRule ^ %1/ [R=301,L]
Considering that your htaccess rules file have more rules apart from your shown ones, which will take care of handling pages from backend(rewrite), if this is the case then please try following htaccess rules file.
Please these rules at top of your htaccess rules file. Also make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /example.com/
RewriteRule ^home/(.*)$ /$1 [R=301,L]
Here is my current .htaccess and remember I need some .htaccess that can destroy my current .htaccess.
Current .htaccess:
RewriteRule ^join$ https://example.com/internalpath/join/index.php [L,QSA]
RewriteRule ^join/(.*)$ https://example.com/internalpath/join/$1 [L,QSA]
Now my problem:
I want to redirect each and every file and directories to HTTP, except these two:
https://example.com/join/
https://example.com/join
Remember, I want every link on http except this above provided link, other then all files and directories and even files and directories in /join/ or /join will be HTTP, just two links on HTTP, but please it will not destroy the previous written .htaccess.
Above thr rules that you have add this:
RewriteCond %{HTTPS} on
RewriteRule !^join/?$ http://domain.com%{REQUEST_URI} [L,R=301]
I have an htaccess file that I want to redirect the all pages to the another folder. I am using cakephp for the site, except for this folder which I want to redirect.
"/app/webroot/" is added to the new directory so the url is /app/webroot/new/ instead of just new.
I am placing this htaccess file (below) in the "new" directory and want anything at /app/webroot/new/ to redirect to /new/ and remove the /app/webroot/ This folder is independent of cakephp and thus does not need to be processed by cake.
The code below loops and I am not sure why.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /new/
# If your concerned about direct access to a particular page without the sub-dir
# you will want to add something like this
RewriteCond %{REQUEST_URI} !^/new
RewriteRule (.*) /new/$1 [R=301,L,NC]
You should NOT place the .htaccess file in /new/ but in /app/webroot/new/.
Could someone tell me how to rewrite this URL. I have looked at a lot of questions on stackoverflow but they seem to be missing my answer.
RewriteEngine On
That is what I have... its a bit poor.
I need to rewrite url's if they do not point to a directory.
I need to do this...
any.domain.com/pages/some-page-slug/login
To be rewritten to the correct url of...
any.domain.com/pages/login.php?page=32
Does anyone have any ideas on how this can be achieved?
1) Rewriting product.php?id=12 to product-12.html
It is a simple redirection in which .php extension is hidden from the browser’s address bar and dynamic url (containing “?” character) is converted into a static URL.
RewriteEngine on
RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1
2) Rewriting product.php?id=12 to product/ipod-nano/12.html
SEO expert always suggest to display the main keyword in the URL. In the following URL rewriting technique you can display the name of the product in URL.
RewriteEngine on
RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ product.php?id=$2
3) Redirecting non www URL to www URL
If you type yahoo.com in browser it will be redirected to www.yahoo.com. If you want to do same with your website then put the following code to .htaccess file. What is benefit of this kind of redirection?? Please check the post about SEO friendly redirect (301) redirect in php and .htaccess.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^optimaxwebsolutions\.com$
RewriteRule (.*) http://www.optimaxwebsolutions.com/$1 [R=301,L]
4) Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz
Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e http://yoursite.com/xyz to http://yoursite.com/user.php?username=xyz then you can add the following code to the .htaccess file.
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
5) Redirecting the domain to a new subfolder of inside public_html.
Suppose the you’ve redeveloped your site and all the new development reside inside the “new” folder of inside root folder.Then the new development of the website can be accessed like “test.com/new”. Now moving these files to the root folder can be a hectic process so you can create the following code inside the .htaccess file and place it under the root folder of the website. In result, www.test.com point out to the files inside “new” folder.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.test\.com$
RewriteCond %{REQUEST_URI} !^/new/
RewriteRule (.*) /new/$1
TO do this you need to write a front controller.
See here, here, here, and here.
Alternatively in Apache you can rewrite this
any.domain.com/pages/32/login
or this:
any.domain.com/32/login
or even this:
any.domain.com/some-slug/32/login
to this:
any.domain.com/pages/login.php?page=32
One way or another to do this with only apache you need to supply the page id in some fashion. Keep in mind even with format any.domain.com/some-slug/32/login the content of the slug is irrelevant and won't necessarily link to the correct page. Which I imagine is undesirable and bad for SEO.
Another alternative is using RewriteMap. But this will be tricky and require reloading apache configurations whenever a page/slug is created/edit.
I understand that pages and login are static in this case and some-page-slug is changing. And you always want to redirect to static page /pages/login.php?page=32
So this is how to do it:
1) Rewrite
RewriteEngine On
RewriteRule ^pages/([a-zA-Z0-9_]+)/login(.*)$ /pages/login.php?page=32
or 2) Redirect Pernament
RewriteEngine On
RewriteRule ^pages/([a-zA-Z0-9_]+)/login(.*)$ /pages/login.php?page=32 [R=301,L]
or 3) Redirect Temporary
RewriteEngine On
RewriteRule ^pages/([a-zA-Z0-9_]+)/login(.*)$ /pages/login.php?page=32 [R=302,L]
Here is great article about htaccess trics
http://perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/