Can we write .htaccess for two different dynamic pages like product.php & blog.php in php mysql? - apache

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/?-([^/]+)? product-details.php?pro_slug=$1&id=$2 [L,QSA]
RewriteRule ^([^/]+)/?-([^/]+)? blog-details.php?n_slug=$1&n_id=$2 [L,QSA]
this will working for only first defined page product-details.php. please help.
I am hitting on www.test.com/blog/Want-to-transfer-your-home-loan-to-another-bank, www.test.com/product/agriculture-land-near-by-agra First url should be served by product-details and 2nd one should be served by blog-details.php file.

Based on your shown samples, please try following htaccess Rule file.
Make sure to clear your browser cache before testing your URLs.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(blog)/([\w-]+)/?$ product-details.php?pro_slug=$1&id=$2 [NC,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(product)/([\w-]+)/?$ blog-details.php?n_slug=$1&n_id=$2 [NC,L,QSA]

Related

Rewrite a path with htaccess taking parameters too

I would like to rewrite a path of my website using htaccess mod rewrite, taking the parameters too. So, I want that my website executes something like this:
mysite.com/chat.php?a=text&b=1&c=2&d=text
When I write this path:
mysite.com/chat/text/1/2/text
How can I do this?
This is my htaccess now, but it doesn't work:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^chat/([a-z]+)/([0-9]+)/([0-9]+)/([a-z]+)$ chat.php?n=$1&c=$2&s=$3&b=$4 [QSA]
Could you please try following, written and tested with shown samples only.
Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)$ $1.php?a=$2&b=$3&c=$4&d=$5 [L]
OR to look for URLs specifically starting with chat try following. Please make sure either you use above OR following set of Rules one at a time only.
RewriteEngine ON
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(chat)/([^/]*)/([^/]*)/([^/]*)$ $1.php?a=$2&b=$3&c=$4&d=$5 [NC,L]

image is not loading , .htaccess file problem

Someone tell me, where i'm doing wrong . this is my .htaccess file code
Options -Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)/$ /$1 [R=301,L]
RewriteRule ^(.*)$ Core/index.php?app=$1 [QSA,L]
Here everything looks good. every request go to Core/index.php file. but when I type a URL to any file ( images, video ...) which is in current server, then file is not loading in browser. instead of file loading , it loads index.php page again (I found in Network panel of the browser)
Could you please try following, based on your shown attempts. You should write rule of removing / at last before your other rule of rewriting.
Please make sure to clear your browser cache before testing your URLs.
Options -Indexes
RewriteEngine on
RewriteRule ^(.*)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ Core/index.php?app=$1 [QSA,L]

How to redirect URL into a new URL using .htaccess?

I want to redirect pages using .htaccess. I am using code igntiter
When user type this URL in addresss bar :
form.bixy.com/salesapp
and they hit enter button, the URL should changed into:
form.bixy.com/salesapp/administrator/addusr
I have this .htaccess inside the salesapp folder
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|images|stylesheets|system/application/sources/)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/
</IfModule>
If the line RewriteRule ^(.*)$ index.php?/ is removed, I got The requested URL was not found on this server.
I have little knowledge about .htaccess. Any help is greatly appreciated, thanks in advance.
Edit:
This is my current .htaccess that I put inside salesapp folder:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|images|stylesheets|system/application/sources/)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php [L]
RewriteRule ^/? /salesapp/administrator/addusr[NC,R=301,L]
</IfModule>
It still give me error, but the URL should've worked
The page isn’t redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
Inside salesapp you can try this .htaccess:
RewriteEngine on
RewriteBase /salesapp/
RewriteRule ^(?:administrator)?/?$ administrator/addusr [R=301,L,NC]
RewriteCond $1 !^(index\.php|images|stylesheets|system/application/sources/) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php [L]

Renaming file in URL (.php file)

I have a file called filename-step1.php and looking to make the url domain.com/filename/step1 through .htaccess.
My current .htaccess file looks like:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
At the moment, this works fine for removing the .php tag from the url. Just need to fix the directories.
You could add a RewriteRule to redirect to $1/$2.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)$ /$1-$2.php [NC,L]
</IfModule>
So, filename/step1 will trigger the filename-step1.php file.
I am giving 2 solutions here, please try one at a time only in your .htaccess file. With your shown samples, could you please try following as a Generic rules.
RewriteEngine ON
RewriteCond %{HTTP_HOST} domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/(.*)/?$ $1-$2.php [NC,L]
OR in case you are looking for specifically url filename/step1 try following.
RewriteEngine ON
RewriteCond %{HTTP_HOST} domain\.com [NC]
RewriteRule ^(filename)/(step1)/?$ $1-$2.php [NC,L]

How to rewrite the get variables using htaccess?

I have a htaccess file that rewrites the link
http://www.example.com/profiles.php?view_user=test
to
http://www.example.com/profiles?view_user=test
but i want to rewrite the remaining get variable --
profiles?view_user=test
to
profiles/view_user/test
help me out i dont know much of htaccess
Try adding these rules to the appropriate place in the htaccess file in your document root:
RewriteCond %{THE_REQUEST} \ /+profiles\.php\?([^=&]+)=([^&\ ]+)
RewriteRule ^ /profiles/%1/%2? [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^profiles/([^/]+)/([^/]+)/?$ /profiles.php?$1=$2 [L,QSA]
Also make sure you have multiviews turned off:
Options -Multiviews
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(profiles)/([^/]+)/([^/]+)/?$ /$1.php?$2=$3 [QSA,L,NC]