Subdomain, Pagination and .htaccess - .htaccess

in the name of God
hi,
How i can transform this url
domain.tld/blog.php?name=username&page=2
to this one
username.domain.tld/page/2
with .htaccess?

add the following directives to .htaccess file (create it if it does not exist) in the root directory of your website (domain.tld)
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} name=([^&]+)
RewriteCond %{QUERY_STRING} page=([^&]+)
RewriteRule ^blog.php$ http://%1.domain.tld/page/%2? [R=301,L,NC]

Related

Htaccess rewrite in subfolder with parameters

I'm trying to rewrite /streams/post.php?id=1 into /streams/thread/1 .
I did find some codes for .htaccess with parameters but it didn't work in the subfolder.
Also, should I put another .htaccess in the subfolder or use the one on the main directory? ( /.htaccess or /streams/.htaccess)
Also, in the past when I've rewritten, sometimes it redirects from for example /streams/thread/1 to /streams/post.php?id= and sometimes it actually displays /streams/thread/1 in the URL, I would like it to display /streams/thread/1 in the URL, not just redirect.
You can put your htaccess in root or streams folder (that's up to you).
In root folder
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/streams/post\.php\?id=([0-9]*)\s [NC]
RewriteRule . streams/thread/%1? [R=301,L]
RewriteRule ^streams/thread/([0-9]+)$ streams/post.php?id=$1 [L]
In streams folder
RewriteEngine On
RewriteBase /streams/
RewriteCond %{THE_REQUEST} \s/streams/post\.php\?id=([0-9]*)\s [NC]
RewriteRule . thread/%1? [R=301,L]
RewriteRule ^thread/([0-9]+)$ post.php?id=$1 [L]

htaccess redirect subfolder

I would like to redirect the url http://intranet/trac/paradox/report/6 to http://cobra.woking/trac/paradox/report/6. trac is a subfolder and paradox is a subfolder. report/6 are params that need to be kept and may change.
In my apache doc root i have
#/opt/html/.htaccess
Redirect 301 / http://intranet/intranet
RewriteEngine On
RewriteRule ^trac/paradox/report/6$ http://cobra.woking/trac/paradox/report/6 [L,R]
I have tried the following which does not work
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^intranet$
RewriteRule (.*) http://cobra.woking/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^intranet$
RewriteRule (.*) http://cobra.woking/$1 [R=301,L]
URL i want to change is http://intranet/trac/paradox/ to http://cobra.woking/trac/paradox/. I have placed .htaccess in the /opt/html/trac/paradox/.htaccess
In the htaccess file of your intranet's document root, add this to the top of the file:
RewriteEngine On
RewriteRule ^trac/paradox/report/6$ http://cobra.woking/trac/paradox/report/6 [L,R]

Redirect url with .htaccess

I m sure that many people will say that this is duplicated but I try everything from other "Question"`s and nothings work for me.
The problem is that I move my project to the web server.
In this server I have folder "public_html" where I but my project Symfony.
Now to enter on my project I must write the following url: www.mydomain.com/Symfony/web/*
But I want to write a Rewrite Rule which will redirect from www.mydomain.com/Symfony/web/* to
www.mydomain.com/home/*.
To do this I try on 2 different ways with many combination of ReWrite rule.
In my public_html I create a .htaccess folder
I edit the .htaccess in Symfony/web folder
I add the following rule in both file but without success
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^Symfony/web/(.*)$ www.mydomain.com/home/$1 [L,R=301]
Unfortunately without success. What I`m doing wrong?
My htaccess file look like
And all the time Error 404 Object not found
Symfony/web/.htaccess
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Symfony/web/
RewriteCond %{THE_REQUEST} \s/+Symfony/web/ [NC]
RewriteRule ^(.*)$ /home/$1 [L,R=301]
RewriteRule ^home/(.*)$ $1 [L,NC]
</IfModule>
It`s redirecting me but I receive again Object not found :(
I delete the .htaccess in public_html folder which is the root one for my server
public_html\.htaccess
RewriteEngine On
RewriteRule ^home/(.*)$ /Symfony/web/$1 [L,NC]
1: Place this code in /Symfony/web/.htaccess:
RewriteEngine On
RewriteBase /Symfony/web/
RewriteCond %{THE_REQUEST} \s/+Symfony/web/ [NC]
RewriteRule ^(.*)$ /home/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [L]
2: Place this code in /public_html/.htaccess:
RewriteRule ^home/(.*)$ /Symfony/web/$1 [L,NC]
I'm going to go out on a limb and say that your rule is backwards. I think you want your URL to be www.mydomain.com/home/* in the browser... In which case the rule would be reversed. Also, your .htaccess should be in the root and you don't need to include the domain in the rewrite rule because you set a rewrite base.
RewriteRule ^home/(.*)$ Symfony/web/$1 [L,R=301]

Redirect specific page with query using htaccess

for example
mydomain.com/jobresultpage?what=&where=Arkansas
redirect to
yourdomain.com/jobresultpage?what=&where=Arkansas
but other page like
mydomain.com/about.html
mydomain.com/contact.html
not redirect..
Try adding the rules below to the .htaccess file located in the root directory of mydomain.com
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} mydomain\.com$ [NC]
#redirect any request for jobresult to yourdomain
RewriteRule ^jobresultpage$ http://yourdomain.com%{REQUEST_URI} [NC,L,R=301]

.htaccess redirect subdomain

I want to allow the users to type
xyz.example.com
in order to reach
test.php?id=xyz
What code should I use to accomplish my goal?
Try adding the following to your htaccess file in the root directory of your example.com domain
RewriteEngine on
RewriteBase /
#if the host is anything.example.com
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
#send all requests to test.php
RewriteRule .* test.php?id=%1 [L]

Resources