I am asking question after so many attempts to do this. Found many results on this website but none of them worked for me.
I have a website built in PHP (no any CMS) that has URLS like
www.someweb.com/job_detail.php?job_id=123456789
I just want to convert all URLS like these
www.someweb.com/123456789
Here is my .htaccess content:
DirectoryIndex index.php
RedirectMatch 404 ^/admin/$
RedirectMatch 404 ^/admin/uploads/$
ErrorDocument 404 /page_not_found.php
<Files index.php>
Order deny,allow
deny from all
allow from all
</Files>
Please tell me how to do this? I think I need to do some change in just .htaccess
Try this:
RewriteEngine on
RewriteRule ^([0-9]+)/?$ /job_detail.php?job_id=$1 [L]
RewriteEngine on
RewriteRule "^([0-9]+)$" "job_detail.php?job_id=$1" [L]
Related
I'm new in SS and I need to moved one website from one web hosting into Godaddy.
Ir order to do that I have installed SS in my local environment in the root folder and everything works smoothly. Then I went to the subdomain and almost everything works well except the detail page. For example:
Home page: http://subdomain.domain.com.au/subdomain/index.php/ - IT WORKS
Product - Tools page: http://subdomain.domain.com.au/subdomain/index.php/products/tools/ - IT WORKS
Tools details page: http://subdomain.domain.com.au/tools/show/slp20xp IT DOESN'T WORK.
If I go to this URL : http://subdomain.domain.com.au/subdomain/index.php/products/tools//show/slp20xp The page is there and working fine. Somehow, on the detail page is trying to go one step backward to the root folder. If I moved this page to the root folder everything works fine.
Any idea what I might be missing? I tried different htacces configuration but none of them seems to work.
### SILVERSTRIPE START ###
<Files *.ss>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>
<Files web.config>
Order deny,allow
Deny from all
</Files>
# This denies access to all yml files, since developers might include sensitive
# information in them. See the docs for work-arounds to serve some yaml files
<Files *.yml>
Order allow,deny
Deny from all
</Files>
ErrorDocument 404 /assets/error-404.html
ErrorDocument 500 /assets/error-500.html
<IfModule mod_alias.c>
RedirectMatch 403 /silverstripe-cache(/|$)
RedirectMatch 403 /vendor(/|$)
RedirectMatch 403 /composer\.(json|lock)
</IfModule>
<IfModule mod_rewrite.c>
SetEnv HTTP_MOD_REWRITE On
RewriteEngine On
RewriteBase '/'
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule .* framework/main.php?url=%1&%{QUERY_STRING} [L]
</IfModule>
### SILVERSTRIPE END ###
In the htaccess of the subdomain, try changing RewriteBase '/' to RewriteBase '/subdomain'
I have this URL pointing my web site:
http://www.mysite.ext/.htaccess.aspx-->/
and I like to redirected to
http://www.mysite.ext/
but I can't.
In my .htaccess file I have enter this rule:
RewriteRule ^(.htaccess(.+))/?$ http://www.mysite.ext/? [R=301,L]
but doesn't work
also I have try the following:
RewriteRule ^(\.htaccess\.aspx(.*))/?$ http://www.mysite.ext/? [R=301,L]
but still no luck. I don't know if that helps, but the site is based on PHP.
Any idea please ?
Is it realy so hard ?
Can somebody to help me please ?
Not sure how you are you getting requests for /.htaccess.aspx and why you want to redirect them.
However keep in mind that Apache configs usually block access to .htaccess using directive like below:
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
That throws 403 (Forbidden) error for any request that starts with /.ht.
Workaround:
Have a custom handler for 403:
ErrorDocument 403 /errorPage403.php
and have this redirect rule:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+\.htaccess\.aspx [NC]
RewriteRule ^ /? [L,R]
I'm new to rewriting urls and wanted to know how i would rewrite
From this
/profile/4
To this
/profile.php?id=4
I have this rule so far
RewriteRule ^profile/([0-9]+)/?$ profile.php?id=$1
but it displays this in the browser
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
It displays /profile/4/index.php in the browser address bar which is incorrect.
.htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
Options +FollowSymlinks
RewriteEngine on
#ErrorDocument 404 /test.php
DirectoryIndex test.php
RewriteRule settings editProfile.php
RewriteRule update update.php
RewriteRule home test.php
RewriteRule ^profile/([0-9]+)/?$ profile.php?id=$1
You are pretty much there. Try using this instead
RewriteRule ^profile/(.*)$ profile.php?id=$1
I found this good free resource online to help you test your rewrite rules before you post them to your live site. This may help for the future. It looks like your rule should work as you have it posted though. The problem must be somewhere else.
Your rule is just fine so there's a redirection somewhere conflicting with it. I suppose that you don't have a real directory at /profile/4 so they main candidate left is mod_negotiation. Try this:
Options -MultiViews
I have an issue with htaccess that is blocking php script access.
this is the error message I receive when i load up the page:
You don't have permission to access /index.php on this server.
When i remove the .htaccess file i can access index.php with no issues.
The same .htaccess file was working fine on a different hosting that i use.
My .htaccess file (EDIT: rearranged after suggestion by toopay)
RewriteEngine On
<Files .*>
Order allow,deny
Allow from all
</Files>
Options FollowSymLinks
RewriteRule ^photos.+$ thumbs.php [L,QSA]
RewriteRule ^[a-zA-Z0-9\-_]*$ index.php [L,QSA]
RewriteRule ^[a-zA-Z0-9\-_]+\.html$ index.php [L,QSA]
I did try to set the file priviledges to 644, 755, 777 and still not working with any settings.
Could you please help me and see what i have wrong, as this is the first time it is happening and the same .htaccess file is working fine on a different domain (folder) on the same hosting.
Couldn't there be problem with <Files .*>? I think this is a wildcard pattern so you should use just <Files *>.
I managed to find the solution, the issue was really simple, i was missing a + before FollowSymLinks. Simple issue, few wasted hours to find the solution. The weirdest part is that the on the same hosting, different domain/folder it is working the same without the +... Anyway thank you for your help.
this is my final working code:
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^photos.+$ thumbs.php [L,QSA]
RewriteRule ^[a-zA-Z0-9\-_]*$ index.php [L,QSA]
RewriteRule ^[a-zA-Z0-9\-_]+\.html$ index.php [L,QSA]
The order of your htaccess, should be...
RewriteEngine On
<Files .*>
Order allow,deny
Allow from all
</Files>
Options FollowSymLinks
RewriteRule ^photos.+$ thumbs.php [L,QSA]
RewriteRule ^[a-zA-Z0-9\-_]*$ index.php [L,QSA]
RewriteRule ^[a-zA-Z0-9\-_]+\.html$ index.php [L,QSA]
My question is quite simple. I have my main page (www.domain.com/index.php)
Is there a way to redirect the user to /index.php when he only types www.domain.com?
And also remove the index.php from the url when he's on it?
I checked a bit about .htaccess, but none of the tricks seem to do the job.
Thank you!
EDIT
Here's my .htaccess:
# To set your custom php.ini, add the following line to this file:
# suphp_configpath /home/yourusername/path/to/php.ini
DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
<Files .htaccess>
order allow,deny
deny from all
</Files>
Options All -Indexes
As you can see, I put DirectoryIndex index.php in it, but doesn't change it :(
Simply put
DirectoryIndex index.php
in your .htaccess
When the user types www.domain.com it'll take index.php as default index page and won't be display in the address
in the Domain control panel mention Start / Index page as index.php.
Usually index.html/htm is the default page.
You will find these option under site proerties.
Redirect / http:/your.domain.php/index.php
RewriteEngine On
RewriteBase / # URL path corresponding to this directory
RewriteRule (^|.*/)index\.php$ $1 [R]