I am having some issues with url rewriting
I am using this as my code for rewrite in htaccess
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /pages.php?id=$1 [L]
this was my url
studentsassignmenthelp.com/pages.php?id=Marketing-Assignment-Help
after using the url rewrite i am getting this
studentsassignmenthelp.com/Marketing-Assignment-Help.html
but i need it without the html like the below one
studentsassignmenthelp.com/Marketing-Assignment-Help
if i use the below code to remove the .html than it shows error 500 server...
RewriteRule ^([^/]*)$ /pages.php?id=$1 [L]
I saw some example but after using them it shows 404 or 500 error
Try this,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !pages.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ pages.php?id=$1 [QSA,L]
try this:
RewriteEngine On
RewriteRule ^([^/]*)$ /pages.php?id=$1 [L]
redirectMatch 301 ^(.*).html $1
This is quite usefull to remove any url extension and avoid broken links.
Related
I am trying to make a rewrite rule that will rewrite this:
example.com/audio.mp3
To this:
example.com/stats.php?file=audio.mp3
I have:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ file.php?file=$1 [QSA]
This is working as long as I don't add a file extension to the URL. As soon as I do, I get a 404 not found page.
What's wrong?
If you put this above your other lines of code, I do believe it should work:
RewriteRule ^(.*)\.mp3$ /stats.php?file=$1 [L]
Im trying to achieve this
http://domain.com?q=page-slug to http://domain.com/page-slug
right now if I access this http://domain.com?q=page-slug my webpage is working, but I want clean URls like http://domain.com/page-slug
I used this code in my htaccess but returning 500 error
RewriteEngine On
RewriteRule ^(.*)$ ?q=$1 [L,QSA]
any help please.
Try this I am assuming you have index.php page which is handling the request.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)$ index.php?q=$1 [QSA,L]
If not index.php change to actual page you have.
Original url : mydomain/index.php?lang=english
I want url : mydomain/english
My .htaccess file below :
RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?lang=$1 [L]
But I get 500 internal server error. How can I solved this problem ?
Thanks.
What about this:
RewriteRule ^([^/]+)$ ?lang=$1 [L] # and maybe QSA too
The rewrite engine loops until the URI stops changing. Try adding some conditions:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /index.php?lang=$1 [L]
I am trying to rewrite the following URL via .htaccess:
http://website.com/dealer_home.php?id=dealer1
The result I am aiming for is this, where dealer1 is the username which is set as variable:
http://website.com/dealer1
I have tried this rule in .htaccess:
RewriteEngine On
RewriteRule ^([^/]*)$ /dealer_home.php?id=$1 [L]
However I get "Internal Server Error" message when trying to load any of the website pages.
Can you provide some advice where I am doing wrong?
EDIT:
I tried also RewriteRule ^(.*)$ dealer_home.php?id=$1 [PT] but no success.
Thank you!
Maybe it's a conflict with existing files/folders and root uri.
Try this code instead
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ /dealer_home.php?id=$1 [L]
This rule will match every url like domain.com/something if something is not an existing file or folder.
So if you have other rules then you should put them above this one.
EDIT: to avoid duplicate content and to redirect old format to new url format
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/dealer_home\.php\?id=([^&\s]+)\s [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ /dealer_home.php?id=$1 [L]
I am currently trying to write a rewrite rule. I want to simplify the entered URL so that it will always use the index. The input url would be www.example.com/home.php and would be rewritten to www.example.com/index.php?r=page/home.
I wrote this .htaccess file:
RewriteEngine On
RewriteRule ^([^/]*)\.php$ /index.php?r=page/$1 [L]
This configuration unfortunately gives me an error 500. I can understand that it is caused by the fact that if I enter index.php for instance, apache will not know if it must use the index.php file or use the rewritten url index.php?r=page/index.
Is it possible to accomplish this kind of rewriting rule with apache? If so, how can I fix my error 500?
Edit: Please note that the RewriteRule works fine if I change the extension .php to anything else such as .html, as so: RewriteRule ^([^/]*)\.html$ /index.php?r=page/$1 [L]
You have two possibilities.
First one
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule ^([^/]+)\.php$ /index.php?r=page/$1 [L]
Second one
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /([^/]+)\.php
RewriteRule ^.*$ /index.php?r=page/$1 [L]
you can also try with this :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?r=page/$1 [L]