Trouble with redirecting to an absolute_uri - django

I'm attempting to redirect to a full url
current url is an absolute_uri
currenturl = request.GET.get('currenturl') #lets say this resolves to http://www.google.com/
return redirect(currenturl)
This sends me to an 404 error page as it's trying to resolve the following url
http://localhost:8000/accounts/profile/calendar/delete/15/'http://www.google.com/'

I was passing the absolute uri in the template into the currenturl with single quotes around it. I had to remove the single quotes.

Related

Remove last part of URL with regex

I have lot of URL links that looks like:
https://www.example.com/category/product_name?product_rewrite=product_name
I am trying to redirect them to:
https://www.example.com/category/product_name
I have a module in Prestashop where I can put regex for redirect old to new URL.
I am trying with:
OLD URL: https://www.example.com/(.)\?product_rewrite=(.)
New URL: https://www.exampe.com/(.*)\
Unfortunately above is not working and can not find why - because module is not working properly or because I am giving wrong data.

Redirect url if Contains Query String to new URL and Pass Sting

I have a url https://example.com/registration-free/?member_id=1234&code=0e9236c500453e3c624ca96939f8aabf and this is a conformation link for a subscription process, but I want to locate this to another page and pass the variables, using regex in either htaccess or yoast pro for wordpress
the new page would be https://example.com/registration-step3/?member_id=1234&code=0e9236c500453e3c624ca96939f8aabf
But if someone goes to the page https://example.com/registration-free/ and there is no query string I don't want to redirect them.
Is this possible, so to clarify, if the initial page has no query string it doesn't redirect, but if a query string is present it redirects and passes the variables to the new url, using htacces or regex in wordpress yoast pro

Django url pattern doesn't match

I am using new Django 1.8 app to learn Django.
I am stumped as to how to get this my simple url to be resolved by urls.py
I create the url in another view as:
<a href="/photoview/{{photo.id}}/"}>
I can successfully pass this url to the browser as:
http://localhost:8000/photoview/300/
I am expecting that this url can be matched by the urls.py expression:
url('r^photoview/(?P<id>\d+)/$', views.photoview),
But this is not working. I have tried variations of this but none have worked so far, such as:
url('r^photoview/(?P<id>[0-9]+)/$', views.photoview),
I get this message in browser when it fails to match
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/photoview/300/
Using the URLconf defined in asset.urls, Django tried these URL patterns, in this order:
^admin/
^$ [name='index']
^time/$
^about/$
^accounts/$
^photos/$
^tags/$
^users/$
r^photoview/(?P<id>\d+)/$
^static\/photos\/(?P<path>.*)$
The current URL, photoview/300/, didn't match any of these.
Appreciate any help getting this to work.
you have url('r^photoview/(?P<id>\d+)/$', views.photoview),
you want url(r'^photoview/(?P<id>\d+)/$', views.photoview),
(Note the r is in front of the string, not the first character)
As noted in docs.djangoproject.com/en/1.8/topics/http/urls,
The 'r' in front of each regular expression string is optional but
recommended. It tells Python that a string is “raw” – that nothing in
the string should be escaped
Also note that you should use a friendly name in your url definition (e.g. photoview) and then use {% url 'photoview' photo.id %} in your template instead of hardcoding the URL pattern.

Django url dispatcher page not found

i am trying to define a url pattern in django urls.py like
url(r'^networking$','mysite1.networking.views.networking'),
when i am typing http://myhost.com/networking in my address bar to go to networking page
i am getting 404 error and a slash '/' automatically added to the address bar like
http://myhost.com/networking/
help me out what i am doing wrong?
You probably aren't including your urlconf correctly. The behavior you're seeing is because of APPEND_SLASH is set to True by default when Django can't resolve the url.
Either set Append_Slash to false which is true by default or use your url description like given below which redirect url with slash to desired view.
url(r'^networking/$','mysite1.networking.views.networking'),
Seems your Apache server or some Django middleware is adding trailing slashes. You can either correct that, or the better way is you can use the following url pattern:
url(r'^networking/?$','mysite1.networking.views.networking'),

Check if a URL is still active or Permanently Moved

Is there a way to check if a URL still active or it returns a 301 Redirect code using chhttp?
You've answered your own question - use CFHTTP.
<cfhttp method="head" url="http://www.google.com" result="myResult">
<cfdump var="#myResult#">
You'll see that myResult struct contains "Responseheader" struct with "Status_Code" field in it. It will contain the numeric status code.
If you don't need numeric you can just use myResult.Statuscode - returns something like "200 OK".
If the url will be incorrect or there will be some issues with reaching the target, the "Responseheader" will be empty.
Addendum after the comment:
If you want to know the redirect location after 301 use CFHTTP with trace or options as method.
<cfhttp method="trace" url="http://www.google.com" result="myResult">
The result should contain the "Status_Code" as above as well as "Location" - the url to redirect to.
You have to use the redirect attribute (e.g. redirect="false") in cfhttp tag. Then you get the original response and can figure out what http code was sent back to your request.