Replacing link with .htaccess - .htaccess

I am trying to replace link but ending with internal server error
www.domain.com/profile.php?id=1
i want it to ->
www.domain.com/1
.htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^login\.php\/?(.*)$ "http\:\/\/domain\.com\/$1" [R=301,L]
RewriteRule ^([^/]*)$ /profile.php?id=$1 [L]

You just have to use this code :
RewriteEngine on
RewriteRule ^([0-9]+)$ /profile.php?id=$1 [L]

Related

.htaccess RewriteRule subsubdomain.subdomain.domain.tld to subdomain.domain.tld/subsubdomain

Is it posible to redirect a sub-subdomain into a subdomain with the sub-sub domain as new folder using .htaccess rewrite-rule?
For example... When i go to 2013.archive.example.com I want to end up in archive.example.com/2013..
Already tried some things, current .htaccess is:
RewriteRule On
RewriteCond %{HTTP_HOST} ^(.*)\.archive\.example\.com$
RewriteRule ^(.*)$ archive.example.com/%1/$1 [L]
Unfortunately it isn't working. Any suggestions for this?
Changed it a but, currently using:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.archive\.example\.com$ [NC]
RewriteRule ^(.*)$ %1/$1 [L]
and is working exactly how I wanted:)
For external redirect: (URL change in browser)
You can use this rule in your DOCUMENT_ROOT/.htaccess:
RewriteCond %{HTTP_HOST} ^([^.]+)\.(archive\.example\.com)$ [NC]
RewriteRule ^ http://%2/%1%{REQUEST_URI} [L,R=301]
This will work provided DOCUMENT_ROOT is same for anything.archive.example.com and archive.example.com.
For internal forward: (No URL change in browser)
You can use this rule in your DOCUMENT_ROOT/.htaccess:
RewriteCond %{HTTP_HOST} ^([^.]+)\.archive\.example\.com$ [NC]
RewriteRule ^ /%1%{REQUEST_URI} [L]
If they share the same root, then you don't need the archive.example.com part in your rule's target:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.archive\.example\.com$ [NC]
RewriteRule ^(.*)$ /%1/$1 [L]

.htaccess RewriteRule without URL change in browser

I have .htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^somedomain.com [NC]
RewriteRule ^(.*)$ http://www.somedomain.com/$1 [R=301,NC]
RewriteRule ^r/(.*)$ index.php?rid=$1 [NC]
But last condition performs redirect in browser when I request URL like www.somedomain.com/r/123 and show me URL like www.somedomain.com/index.php?rid=123. But I need call this script without URL change.
What's wrong?
You used the R=301 Try to use L just like following:
RewriteCond %{HTTP_HOST} ^somedomain.com [L]
RewriteRule ^(.*)$ http://www.somedomain.com/$1 [L]
RewriteRule ^r/(.*)$ index.php?rid=$1 [L]

.htaccess rewrite to redirect root subdirectory to another subdirectory

Trying to get
www.example.com/alpha
to
www.example.com/beta
I am trying this but its not working
RewriteEngine on
rewritecond %{http_host} example.com/alpha [nc]
rewriterule ^(/)?$ beta [L]
Try this:
RewriteEngine on
RewriteCond %{http_host} example.com\alpha$
RewriteRule \beta$ - [L]
For More Information: Click Here
http://wiki.apache.org/httpd/RewriteCond

htaccess for codeIgniter

I'm trying to redirect a user to /hd/142 if they don't have /hd/ in the URL. I've tried so many options and most of them just redirected me over and over again. Here is the current .htaccess that I have setup.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js)
RewriteRule ^hd/(.*)$ /index.php/$1 [L]
RewriteRule ^(images|css|js)/(.*) /applicationFiles/$1/$2 [L]
Thanks
RewriteEngine on
RewriteBase /
#if url does not have hd in it
RewriteCond %{REQUEST_URI} !^/hd/ [NC]
#redirect to hd
RewriteRule ^ /hd/142 [L,R=301]
#existing rules
RewriteCond $1 !^(index\.php|images|css|js) [NC]
RewriteRule ^hd/(.*)$ /index.php/$1 [L,NC]
RewriteRule ^(images|css|js)/(.*) /applicationFiles/$1/$2 [L]
A simple solution would be to use routes.php in codeigniter:
$route['^(hd)'] = '/hd/142';
Read more under the Regular Expressions section here: http://codeigniter.com/user_guide/general/routing.html

What's wrong with this rewrite rule?

I have this .htaccess:
RewriteEngine On
RewriteRule ^!/(.*)$ path/to/a/file/$1 [L]
RewriteRule ^(.*)$ path/to/another/file/$1 [L]
I want urls in the form of www.website.com/!/this/ to be rewritten to path/to/a/file. Any URL that doesn't match that pattern should be rewritten to path/to/another/file/.
Here's what I've tried to far:
RewriteEngine On
RewriteRule ^!/(.*)$ path/to/a/file/$1 [L]
RewriteCond ...
RewriteRule ^(.*)$ path/to/another/file/$1 [L]
When using the above rewrite rule, I get a 500 - Internal Error.
How can I fix it?
Try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/!
RewriteRule ^!/([a-z0-9_\-\.]+) user/public/$1 [L]
RewriteCond %{REQUEST_URI} !^/!
RewriteRule ^([a-z0-9_\-\.]+)/([a-z0-9_\-\.]+)/?$ $1/controller/front.php/$2 [L]
RewriteCond %{REQUEST_URI} !^/!
RewriteRule ^([a-z0-9_\-]+)/([a-z0-9_\-]+)/([a-z0-9_\-]+)/?$ $1/controller/front.php/$2/$3 [L]

Resources