I am trying to replace a word in URL and redirect the user using .htaccess
I have this link,
/anyword/akram/anyotherword
and I would like to redirect user to
/anyword/tanger/anyotherword
Here is the code I have tried
RewriteRule ^(.*)akram(.*)$ $1tanger$2 [R=301,L]
Edit
Virtualhost:
<Directory /var/www/html/mywebsite.com/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
RewriteRule ^(.+)/akram/(.+)$ http://%{HTTP_HOST}/$1/tanger/$2 [R=301,L]
</IfModule>
</Directory>
</VirtualHost>
You can try this rule.
RewriteRule ^(.+)/akram/(.+)$ http://%{HTTP_HOST}/$1/tanger/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
you should create a new file and save it as .htaccess
After that . Edit the contents of the file. For 301 (Permanent) Redirect: Point an entire site to a different URL on a permanent basis.
# This allows you to redirect your entire website to any other domain
Redirect 301 / http://***/anyword/tanger/anyotherword
I'm answering quite late.
but I think somebody can get it helpful..
RewriteEngine on
RewriteRule /akram/ /tanger/
checkout
Open link, and click on "test"
Related
I've been looking for my answer for 2 days but since I haven't found it, I finally decided to put my question to you.
I'm using a Brinkster shared host and can access the .htaccess but no Apache configuration. Every folder on the server represents the content of one site (domain). In the root I have a .htaccess where every domain is controled with
RewriteCond %{HTTP:Host} ^(?:www\.)?domainname\.be$
RewriteRule (.*) /folder/$1 [NC,L,NS]
In the folder I have another .htacces file.
I want to rewrite and redirect for prettier URLs
http://www.domainname.com/pag.asp?name=var_name&id=var_id
should look like
http://www.domainname.com/name/
The rewrite bit works with the .htaccess code bellow.
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymLinks -MultiViews
Options FollowSymLinks
AllowOverride All
RewriteBase /folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^name=([a-zA-Z-]+)&id=([0-9]+)$ [NC]
RewriteRule ^/?page\.asp$ /%1? [R=301,L]
</IfModule>
But for some reason www.domainname.com/name/ always gives a 404.
What am I doing wrong?
Any help wouldd be highly appreciated.
Thank you
So i have an .htaccess file that has this in it:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteRule ^/path/to/app/(.*)$ /path/to/app/public/$1 [NC,L]
When I go to /path/to/app/ in the browser it displays the directory structure instead of redirecting the server to /path/to/app/public/$1
What am I doing wrong?
Problem is this line:
RewriteRule ^/path/to/app/(.*)$ /path/to/app/public/$1 [NC,L]
Remember: Rewrite doesn't match leading slash. Change your rule to this:
RewriteEngine On
RewriteBase /
RewriteRule ^(path/to/app)/(.*)$ /$1/public/$2 [NC,L]
I think you try build Symfony application? To rewrite rule you need allow override in httpd.conf
DocumentRoot "/var/www/symfony/web"
<Directory "/var/www/symfony/web">
allow from all
AllowOverride All <-------------
Options +Indexes
</Directory>
And if you use directive
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
that mean that if directory exist then display structure else use other RewriteRule
Also try
RewriteRule ^/path/to/app/(.*)$ /path/to/app/public/$1 [QSA,L]
I have this rewrite rule that redirects me to a sub folder and loads the index.html
Options -Indexes
RewriteEngine On
RewriteBase /
SetEnvIf HOST ^sub.mydomain.de allow
Order allow,deny
Allow from env=allow
Satisfy any
RewriteCond %{HTTP_HOST} ^(www.)?sub.mydomain.de$
RewriteRule ^(/)?$ folder [L,R=301]
so far: this works - but it show the /folder/ inside the url - is it possible
to "hide" the /folder/ in url?
Does somebody has an hint for me?.
Thanks
marek
Remove the R=301 bit from the rule so that it looks like this:
RewriteRule ^(/)?$ folder [L]
I want redirect all requested files from folder-a to folder-b. E.g. http://www.yoursite.com/folder-a/index.php to http://www.yoursite.com/folder-b/index.php.
How can I do that? I have verified if mod_rewrite works with this code:
RewriteEngine On
RewriteRule ^google.html$ http://www.google.com/ [R=301]
The structure on the webspace is the following:
.htacces
|-folder-a
|-folder-b
But if I want my folder redirect
RewriteEngine On
RewriteRule ^/folder-a/(.*)$ http://www.yoursite.com/folder-b/$1 [L,R=301]
the redirect doesn't work if I input the following URL:
http://www.yoursite.com/folder-a/
http://www.yoursite.com/folder-a/index.php
The redirect doesn't take place. I stay on the same page ... What I'm doing wrong? I also tried it with this htaccess:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^folder-a(.*)$ http://www.yoursite.com/folder-b$1 [L,R=301]
</IfModule>
If all this works I want to exclude some files. Eg. with this htaccess:
RedirectPermanent /folder-a/info.php /folder-b/new-info.php
Edit:
Now I tried this htaccess
redirectMatch 301 ^/folder-a/ http://www.yoursite.com/folder-b
This works, but I need something which takes the whole path and rewrite it to the new folder.
This for example doesn't work:
RewriteRule ^folder-a/(.*)$ folder-b/$1
Solution
I had an old htacess file in my folder-a so the redirect didn't worked. This is my final htaccess:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^folder-a/excludefile1.php http://www.yoursite.com/folder-b/newnameforfile1.php [L,R=301]
RewriteRule ^folder-a/excludefile2.php http://www.yoursite.com/folder-b/newnameforfile2.php [L,R=301]
RewriteRule ^folder-a/(.*)$ http://www.yoursite.com/folder-b/$1 [L,R=301]
</IfModule>
You probably need to put both rules in place: one for the empty folder and one for other files, and then the catch-all at the bottom. This is not tested:
RewriteEngine On
RewriteRule ^folder-a/info.php http://www.yoursite.com/folder-b/new-info.php [L,R=301]
RewriteRule ^folder-a/ http://www.yoursite.com/folder-b/ [L,R=301]
RewriteRule ^folder-a/(.*)$ http://www.yoursite.com/folder-b/$1 [L,R=301]
I have created a site in a subdirectory and would like the site to appear as if it's in the root.
I used the below Mod_Rewrite code to get the site root to redirect to the subdirectory, but I would like the folder the files are held in to not appear.
currently: www.example.com/sitefiles/content/
Would like: www.example.com/content
Thanks
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^$ /sitefiles/ [L]
RewriteRule (.*) /sitefiles/$1 [L]
If it needs to be done via .htaccess and mod_rewrite, then use this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/sitefiles/
RewriteRule (.*) /sitefiles/$1 [L]
Since you do not explicitly specify the page when website root will be hit, then there is no need for this line: RewriteRule ^$ /sitefiles/ [L]
You need to add condition for your main rewrite rule to prevent rewrite loop (when already rewritten URL gets rewritten again): RewriteCond %{REQUEST_URI} !^/sitefiles/
Well, the directory should have no reason to appear in any listing, and that mod_rewrite you posted should allow you to do as you said. Still, I would go about it a different way:
Options +FollowSymLinks +Indexes
RewriteEngine on
RewriteBase /
RewriteRule ^$ sitefiles/ [L]
RewriteRule ^(.+)$ sitefiles/$1 [L]
Hope this works.